using GMCabsDriverAssistant.Enums; using GMCabsDriverAssistant.Models; using GMCabsDriverAssistant.Models.Rydo; using GMCabsDriverAssistant.Utils; using GMCabsDriverAssistantSolution.Models.Rydo; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Text.Json; using System.Threading.Tasks; using static GMCabsDriverAssistant.Constants; namespace GMCabsDriverAssistant.Services { public class GMCabsDriverService { #region Fields #endregion #region Properties #endregion #region Constructor #endregion #region Methods public async Task ValidateAuthToken(string token, string fcmToken) { ValidateTokenResponseDto validateTokenResponseDto = new ValidateTokenResponseDto(); Uri uri = new Uri($"{BASE_URL}/Auth/ValidateToken"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(new { token, fcmToken }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); validateTokenResponseDto = JsonSerializer.Deserialize(responseData, options); } return validateTokenResponseDto; } public async Task Login(LoginRequestDto loginRequestDto) { LoginResponseDto loginResponseDto = new LoginResponseDto(); try { Uri uri = new Uri(string.Format(BASE_URL + "/Auth/Login", string.Empty)); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(loginRequestDto); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); loginResponseDto = JsonSerializer.Deserialize(responseData, options); if (response.IsSuccessStatusCode) { // DO Nothing } else if (response.StatusCode == HttpStatusCode.BadRequest) { //TODO return loginResponseDto; } else if (response.StatusCode == HttpStatusCode.Unauthorized) { //TODO return loginResponseDto; } } catch (Exception ex) { throw ex; } return loginResponseDto; } public async Task EftposLogin(EftposLoginRequest eftposLoginRequest) { EftposLoginResponse eftposLoginResponse = new EftposLoginResponse(); Uri uri = new Uri(string.Format(BASE_URL_RYDO_API + "/v1/account/eftpos-login", string.Empty)); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(eftposLoginRequest); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); eftposLoginResponse = JsonSerializer.Deserialize(responseData, options); } return eftposLoginResponse; } public async Task GetUnreadNotificationCount(string appToken) { UnreadCountResponseDto unreadCountResponse = new UnreadCountResponseDto(); var unreadNotificationCount = 0; Uri uri = new Uri($"{BASE_URL}/Notifications/UnreadCount?token={appToken}"); Console.WriteLine($"URI: {uri}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); unreadNotificationCount = JsonSerializer.Deserialize(responseData, options); unreadCountResponse.StatusCode = Constant.SUCCESS_CODE; unreadCountResponse.UnreadNotificationCount = unreadNotificationCount; } else { if (response.StatusCode == HttpStatusCode.Unauthorized) { unreadCountResponse.StatusCode = Constant.UNAUTHORIZED_CODE; unreadCountResponse.UnreadNotificationCount = unreadNotificationCount; } else { unreadCountResponse.StatusCode = Constant.BADREQUEST_CODE; unreadCountResponse.UnreadNotificationCount = unreadNotificationCount; } } return unreadCountResponse; } public async Task> GetBookingAvailableCount(string accessToken, string driverId, double lat, double lng) { List bookingIDs = null; Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverId}/available?latitude={lat}&longitude={lng}"); Console.WriteLine($"URI: {uri}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var responseData = await response.Content.ReadAsStringAsync(); List bookings = JsonSerializer.Deserialize>(responseData); if (bookings != null) { bookingIDs = new List(); foreach (BookingDto booking in bookings) { bookingIDs.Add(booking.BookingId); } } } return bookingIDs; } public async Task> GetCoupons(string appToken) { List coupons = new List(); Uri uri = new Uri(string.Format(BASE_URL + "/Coupons?token=" + appToken, string.Empty)); Console.WriteLine($"URI: {uri}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); coupons = JsonSerializer.Deserialize>(responseData, options); } else if (response.StatusCode == HttpStatusCode.BadRequest) { //TODO } else if (response.StatusCode == HttpStatusCode.Unauthorized) { //TODO } return coupons; } public async Task> GetCouponsHistory(string appToken) { List couponsHistory = new List(); Uri uri = new Uri(string.Format(BASE_URL + "/Coupons/History?token=" + appToken, string.Empty)); Console.WriteLine($"URI: {uri}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); couponsHistory = JsonSerializer.Deserialize>(responseData, options); } else if (response.StatusCode == HttpStatusCode.BadRequest) { //TODO } else if (response.StatusCode == HttpStatusCode.Unauthorized) { //TODO } return couponsHistory; } public async Task> GetNotifications(string appToken) { List notifications = new List(); try { Uri uri = new Uri(string.Format(BASE_URL + "/Notifications?token=" + appToken, string.Empty)); Console.WriteLine($"URI: {uri}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage respose = await _httpClient.GetAsync(uri); if (respose != null) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await respose.Content.ReadAsStringAsync(); notifications = JsonSerializer.Deserialize>(responseData, options); } } catch (Exception ex) { throw ex; } return notifications; } public async Task MarkNotificationAsViewed(string appToken, string notificationId) { Uri uri = new Uri($"{BASE_URL}/Notifications/NotificationViewed/{notificationId}?token={appToken}"); Console.WriteLine($"URI: {uri}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PutAsync(uri, null); return response.IsSuccessStatusCode; } public async Task> GetBookings(string accessToken, Guid driverId, double lat, double lng) { List bookings = new List(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverId}/available?latitude={lat}&longitude={lng}"); Debug.WriteLine(uri); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var responseData = await response.Content.ReadAsStringAsync(); bookings = JsonSerializer.Deserialize>(responseData); //if (bookings.Count <= 0) //{ // uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverId}/available?future_bookings=1"); // _httpClient = new HttpClient(); // _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); // response = await _httpClient.GetAsync(uri); // if (response.IsSuccessStatusCode) // { // var featureResponseData = await response.Content.ReadAsStringAsync(); // bookings = JsonSerializer.Deserialize>(featureResponseData); // } //} } bookings = bookings.OrderBy(x => x.FormmattedPickUpDateTime).ToList(); return await Task.FromResult(bookings); } public async Task AcceptBooking(AcceptDeclineBookingRequest acceptBookingRequest, string accessToken, string bookingId) { AcceptDeclineBookingResponse acceptBookingResponse = new AcceptDeclineBookingResponse(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/accept"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(acceptBookingRequest); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.PutAsync(uri, content); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); acceptBookingResponse = JsonSerializer.Deserialize(responseData, options); } acceptBookingResponse.StatusCode = (int)response.StatusCode; acceptBookingResponse.Message = (string)response.ReasonPhrase; return acceptBookingResponse; } public async Task DeclineBooking(AcceptDeclineBookingRequest declineBookingRequest, string accessToken, string bookingId) { AcceptDeclineBookingResponse declineBookingResponse = new AcceptDeclineBookingResponse(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/decline"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(declineBookingRequest); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.PutAsync(uri, content); declineBookingResponse.StatusCode = (int)response.StatusCode; declineBookingResponse.Message = (string)response.ReasonPhrase; return declineBookingResponse; } public async Task SendDriverLocation(string appToken, LocationUpdateRequestDto locationUpdateRequestDto) { Uri uri = new Uri($"{BASE_URL}/DriverAssistantApp/UpdateLocation?token={appToken}"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(locationUpdateRequestDto); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PutAsync(uri, content); return (int)response.StatusCode; } public async Task SendDriverLocationTablet(LocationUpdateRequestDto locationUpdateRequestDto) { Uri uri = new Uri($"{BASE_URL}/DriverAssistantApp/UpdateLocationTablet"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(locationUpdateRequestDto); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PutAsync(uri, content); return (int)response.StatusCode; } public async Task UpdateSilentModeSetting(string appToken, SilentModeSettingRequest request) { Uri uri = new Uri($"{BASE_URL}/DriverAssistantApp/UpdateDriverAppSilentModeSetting?token={appToken}"); string json = JsonSerializer.Serialize(request); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PutAsync(uri, content); return response.IsSuccessStatusCode; } public async Task> GetAcceptedFutureBookings(string accessToken, Guid driverId) { List bookings = new List(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverId}/accepted"); Debug.WriteLine(uri); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var responseData = await response.Content.ReadAsStringAsync(); bookings = JsonSerializer.Deserialize>(responseData); } return await Task.FromResult(bookings); } public async Task GetBookingDetails(string accessToken, Guid bookingId) { BookingDto booking = new BookingDto(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/details"); Debug.WriteLine(uri); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var responseData = await response.Content.ReadAsStringAsync(); booking = JsonSerializer.Deserialize(responseData); } return await Task.FromResult(booking); } public async Task GetAcceptedOnDemandBookingForDriver(string accessToken, Guid driverId) { List booking = new List(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverId}/accepted"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var responseData = await response.Content.ReadAsStringAsync(); booking = JsonSerializer.Deserialize>(responseData); } // there can be only on accepted on demand booking so the below result will either be the only entry or null return await Task.FromResult(booking.FirstOrDefault()); } public async Task UpdateProfile(string appToken, MultipartFormDataContent content) { Uri uri = new Uri($"{BASE_URL}/Driver/UpdateDriverDetails?token={appToken}"); Debug.WriteLine(uri); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); return response.IsSuccessStatusCode; } public async Task GenerateOtp(string mobileNumber) { Uri uri = new Uri($"{BASE_URL}/Auth/GenerateOtp?mobileNumber={mobileNumber}"); Debug.WriteLine(uri); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.PostAsync(uri, null); return response.IsSuccessStatusCode; } public async Task VerifyOtp(string mobileNumber, string otp) { var isOtpValid = false; Uri uri = new Uri($"{BASE_URL}/Auth/VerifyOtp"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(new { mobileNumber, otp }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var responseData = await response.Content.ReadAsStringAsync(); isOtpValid = bool.Parse(responseData); } return isOtpValid; } public async Task UpdateDriverPin(string mobileNumber, int pin) { Uri uri = new Uri($"{BASE_URL}/Auth/UpdateDriverPin"); Debug.WriteLine(uri); string json = JsonSerializer.Serialize(new { mobileNumber, pin }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); return response.IsSuccessStatusCode; } public async Task CouponScan(string appToken, string couponText) { Uri uri = new Uri($"{BASE_URL}/Driver/CouponScan?token={appToken}"); string json = JsonSerializer.Serialize(new { couponText }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); var status = await response.Content.ReadAsStringAsync(); return status.ToString(); } public async Task VoucherScanedCount(string appToken, DateTime reportingDate) { var voucherScanedCount = 0; Uri uri = new Uri($"{BASE_URL}/Coupons/VouchersScannedCount?token={appToken}"); string json = JsonSerializer.Serialize(new { reportingDate }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); voucherScanedCount = JsonSerializer.Deserialize(responseData, options); } return voucherScanedCount; } public async Task LogoutDriverApp(string appToken, double lastLat, double lastLng) { Uri uri = new Uri($"{BASE_URL}/Auth/Logout?token={appToken}&lastLat={lastLat}&lastLng={lastLng}"); string json = JsonSerializer.Serialize(new { }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PostAsync(uri, content); return response.IsSuccessStatusCode; } public async Task DeclineFutureBooking(string accessToken, String bookingId) { bool result = false; Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/release"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); StringContent content = new StringContent("", Encoding.UTF8, "application/json"); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.PutAsync(uri, content); if (response.IsSuccessStatusCode) { result = true; } return result; } public async Task CreateLightDriver(CreateLightDriverRequest createLightDriverRequest) { bool result = false; try { Uri uri = new Uri(string.Format(BASE_URL + "/Auth/CreateLightDriver", string.Empty)); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(createLightDriverRequest); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); if (response.StatusCode == HttpStatusCode.OK) { result= true; } else if (response.StatusCode == HttpStatusCode.BadRequest) { //TODO result= false; } } catch (Exception ex) { result = false; } return result; } public async Task GetLocationVoucherByLocationID(string appToken, int issuedFromLocationID) { LocationVoucherDto locationVoucher = new LocationVoucherDto(); Uri uri = new Uri(string.Format(BASE_URL + "/Coupons/GetLocationVoucherByLocationID?token=" + appToken+ "&issuedFromLocationID=" + issuedFromLocationID, string.Empty)); Console.WriteLine($"URI: {uri}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); locationVoucher = JsonSerializer.Deserialize(responseData, options); } else if (response.StatusCode == HttpStatusCode.BadRequest) { //TODO } else if (response.StatusCode == HttpStatusCode.Unauthorized) { //TODO } return locationVoucher; } public async Task ValidateAdminPassword(string adminPassword) { var isValidAdminPassword = false; Uri uri = new Uri(string.Format(BASE_URL + "/Auth/ValidateAdminPassword?adminPassword=" + adminPassword)); Console.WriteLine($"URI: {uri}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.StatusCode == HttpStatusCode.OK) { isValidAdminPassword = true; } else if (response.StatusCode == HttpStatusCode.BadRequest) { isValidAdminPassword = false; } return isValidAdminPassword; } public async Task ValidateTaxiNumberInstallation(string taxiNumber) { var isValidAdminPassword = false; Uri uri = new Uri(string.Format(BASE_URL + "/DriverAssistantApp/ValidateTaxiNumberInstallation?taxiNumber=" + taxiNumber)); Console.WriteLine($"URI: {uri}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.StatusCode == HttpStatusCode.OK) { isValidAdminPassword = true; } else if (response.StatusCode == HttpStatusCode.BadRequest) { isValidAdminPassword = false; } return isValidAdminPassword; } public async Task StartRiding(StartRideRequest startRideRequest, string accessToken, string bookingId) { StartRideResponse startRideResponse = new StartRideResponse(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/start-ride"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(startRideRequest); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.PutAsync(uri, content); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); startRideResponse = JsonSerializer.Deserialize(responseData, options); } startRideResponse.StatusCode = (int)response.StatusCode; startRideResponse.Message = (string)response.ReasonPhrase; return startRideResponse; } public async Task SendMessage(MessageRequest messageRequest, string accessToken, string bookingId) { ApiResponseDto apiResponseDto = new ApiResponseDto(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/message"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(messageRequest); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var response = await _httpClient.PostAsync(uri, content); apiResponseDto.StatusCode = (int)response.StatusCode; apiResponseDto.Message = (string)response.ReasonPhrase; return apiResponseDto; } public async Task ReleaseBooking(string accessToken, string bookingId) { ApiResponseDto apiResponseDto = new ApiResponseDto(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/release"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(new { }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var response = await _httpClient.PutAsync(uri, content); apiResponseDto.StatusCode = (int)response.StatusCode; apiResponseDto.Message = (string)response.ReasonPhrase; return apiResponseDto; } public async Task NoShowBooking(string accessToken, string bookingId) { ApiResponseDto apiResponseDto = new ApiResponseDto(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/no-show"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(new { }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var response = await _httpClient.PutAsync(uri, content); apiResponseDto.StatusCode = (int)response.StatusCode; apiResponseDto.Message = (string)response.ReasonPhrase; return apiResponseDto; } public async Task NotifyStop(int stopNumber, string accessToken, string bookingId) { Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/notify-stop?stop_number={stopNumber}"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(new { }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.PutAsync(uri, content); return (int)response.StatusCode; } public async Task EndRiding(EndRideRequestDto endRideRequestDto, string accessToken, string bookingId) { ApiResponseDto apiResponseDto = new ApiResponseDto(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/end-ride"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(endRideRequestDto); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var response = await _httpClient.PutAsync(uri, content); apiResponseDto.StatusCode = (int)response.StatusCode; apiResponseDto.Message = (string)response.ReasonPhrase; return apiResponseDto; } public async Task MakePaymentAtTerminal(string bookingId, string driverId, int amount) { ApiResponseDto apiResponseDto = new ApiResponseDto(); Uri uri = new Uri(string.Format(BASE_URL + "/Terminal/PayAtTerminal?bookingID=" + bookingId + "&driverID=" + driverId + "&amount=" + amount)); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(new { }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PutAsync(uri, content); apiResponseDto.StatusCode = (int)response.StatusCode; apiResponseDto.Message = (string)response.ReasonPhrase; return apiResponseDto; } public async Task CloseAccountDriverApp(string appToken) { Uri uri = new Uri($"{BASE_URL}/Driver/CloseAccount?token={appToken}"); string json = JsonSerializer.Serialize(new { }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PutAsync(uri, content); return response.IsSuccessStatusCode; } public async Task UpdateBookingStatus(string appToken, int statusFlag, bool isMetered) { Uri uri = new Uri(string.Format(BASE_URL + $"/DriverAssistantApp/MeterTripStatus?token={appToken}&statusFlag={statusFlag}&isMetered={isMetered}")); string json = JsonSerializer.Serialize(new { }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PutAsync(uri, content); var suburbName = (response.StatusCode == HttpStatusCode.OK) ? await response.Content.ReadAsStringAsync() : String.Empty; return suburbName.ToString(); } public async Task DriverDistress(string appToken, double lat, double lng) { bool result = false; Uri uri = new Uri(string.Format(BASE_URL + $"/DriverAssistantApp/DriverDistress?token={appToken}&lat={lat}&lng={lng}")); string json = JsonSerializer.Serialize(new { }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PutAsync(uri, content); if (response.StatusCode == HttpStatusCode.OK) { result = true; } return result; } public async Task RequestPayment(string appToken, int amount) { Uri uri = new Uri(string.Format(BASE_URL + "/DriverAssistantApp/RequestPayment?token=" + appToken + "&amount=" + amount)); string json = JsonSerializer.Serialize(new { }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PutAsync(uri, content); return response.IsSuccessStatusCode; } public async Task> GetAvailableImeiNumbers(string enteredValue) { List imeiNumers = null; Uri uri = new Uri($"{BASE_URL}/TabletDevice/UninstalledImeis?enteredValue={enteredValue}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); if (responseData != string.Empty) { imeiNumers = JsonSerializer.Deserialize>(responseData,options); } } return imeiNumers; } // now done on logon //public async Task CompleteInstallation(string imeiValue) //{ // bool result = false; // Uri uri = new Uri($"{BASE_URL}/TabletDevice/CompleteTabletInstall?imei={imeiValue}"); // string json = JsonSerializer.Serialize(new { }); // StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); // HttpClient _httpClient = new HttpClient(); // var response = await _httpClient.PutAsync(uri, content); // if (response.IsSuccessStatusCode) // { // // need to handle a false in content result which means some other device has already been installed in the selected taxi // result = true; // } // return result; //} public async Task> GetTripDetails(string appToken) { List tripsBookingResponses = new List(); Uri uri = new Uri(string.Format(BASE_URL + "/DriverAssistantApp/Trips?token=" + appToken)); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); tripsBookingResponses = JsonSerializer.Deserialize>(responseData, options); } return tripsBookingResponses; } public async Task GetLevyBalance(string appToken) { AccountBalanceDto accountBalanceDto = new AccountBalanceDto(); Uri uri = new Uri(string.Format(BASE_URL + "/Driver/AccountBalance?token=" + appToken)); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); accountBalanceDto = JsonSerializer.Deserialize(responseData, options); } return accountBalanceDto; } public async Task GetDriverRatings(string accessToken, string driverId, string phoneNumber) { DriverRatingResponse driverRatingResponse = new DriverRatingResponse(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/drivers?id={driverId}&phone_number={phoneNumber}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); driverRatingResponse = JsonSerializer.Deserialize(responseData, options); } return driverRatingResponse; } public async Task> GetShiftDetails(string appToken) { List shiftResponses = new List(); Uri uri = new Uri(string.Format(BASE_URL + "/DriverAssistantApp/Shifts?token=" + appToken)); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); shiftResponses = JsonSerializer.Deserialize>(responseData, options); } return shiftResponses; } public async Task> GetAvailablePlot(string accessToken, string driverId, double lat, double lng) { List plotResponses = new List(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/available-plot?driver_id={driverId}&lat={lat}&lng={lng}"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.GetAsync(uri); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); plotResponses = JsonSerializer.Deserialize>(responseData, options); } return plotResponses; } public async Task GetPlottedDriverInformation(AvailablePlotRequestDto availablePlotRequest, string accessToken) { AvailablePlotResponseDto availablePlotResponse = new AvailablePlotResponseDto(); Uri uri = new Uri(string.Format(BASE_URL_RYDO_API + "/v1/bookings/driver-plot", string.Empty)); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(availablePlotRequest); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); availablePlotResponse = JsonSerializer.Deserialize(responseData, options); availablePlotResponse.apiResponseDto = new ApiResponseDto(); availablePlotResponse.apiResponseDto.StatusCode = (int)response.StatusCode; availablePlotResponse.apiResponseDto.Message = string.Empty; } else if (response.StatusCode == HttpStatusCode.InternalServerError) { availablePlotResponse.apiResponseDto = new ApiResponseDto(); availablePlotResponse.apiResponseDto.StatusCode = (int)response.StatusCode; availablePlotResponse.apiResponseDto.Message = (string)response.ReasonPhrase; } else { availablePlotResponse.apiResponseDto = new ApiResponseDto(); availablePlotResponse.apiResponseDto.StatusCode = (int)response.StatusCode; availablePlotResponse.apiResponseDto.Message = "Unable to plot in this area"; } return availablePlotResponse; } public async Task RemoveDriverPlot(Guid driverID, string accessToken) { Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverID}/driver-leave-plot"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(new { }); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.PutAsync(uri, content); return (int)response.StatusCode; } public async Task StartTripFutureBooking(StartTripRequest startTripRequest, string accessToken, string bookingId) { StartTripResponse startTripResponse = new StartTripResponse(); Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/head-to-pickup"); Console.WriteLine($"URI: {uri}"); string json = JsonSerializer.Serialize(startTripRequest); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.PutAsync(uri, content); if (response.IsSuccessStatusCode) { var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var responseData = await response.Content.ReadAsStringAsync(); startTripResponse = JsonSerializer.Deserialize(responseData, options); } startTripResponse.ResponseStatusCode = (int)response.StatusCode; startTripResponse.Message = (string)response.ReasonPhrase; return startTripResponse; } public async Task DriverAppSelectedPermissions(string appToken, DriverAppSelectedPermissionsDto request) { Uri uri = new Uri($"{BASE_URL}/DriverAssistantApp/DriverAppSelectedPermissions?token={appToken}"); string json = JsonSerializer.Serialize(request); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpClient _httpClient = new HttpClient(); PutAppVersionInHeader(_httpClient); var response = await _httpClient.PutAsync(uri, content); return response.IsSuccessStatusCode; } #endregion #region Utility private void PutAppVersionInHeader(HttpClient _httpClient) { string[] parts = AppInfo.Version.ToString().Split('.'); string formattedString = parts.Select(p => int.Parse(p).ToString("D2")).Aggregate((p1, p2) => p1 + p2); _httpClient.DefaultRequestHeaders.Add("app-version", formattedString); } #endregion Utility } }