You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1074 lines
51 KiB

1 year ago
  1. using GMCabsDriverAssistant.Enums;
  2. using GMCabsDriverAssistant.Models;
  3. using GMCabsDriverAssistant.Models.Rydo;
  4. using GMCabsDriverAssistant.Utils;
  5. using GMCabsDriverAssistantSolution.Models.Rydo;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Net.Http;
  12. using System.Net.Http.Headers;
  13. using System.Text;
  14. using System.Text.Json;
  15. using System.Threading.Tasks;
  16. using static GMCabsDriverAssistant.Constants;
  17. namespace GMCabsDriverAssistant.Services
  18. {
  19. public class GMCabsDriverService
  20. {
  21. #region Fields
  22. #endregion
  23. #region Properties
  24. #endregion
  25. #region Constructor
  26. #endregion
  27. #region Methods
  28. public async Task<ValidateTokenResponseDto> ValidateAuthToken(string token, string fcmToken)
  29. {
  30. ValidateTokenResponseDto validateTokenResponseDto = new ValidateTokenResponseDto();
  31. Uri uri = new Uri($"{BASE_URL}/Auth/ValidateToken");
  32. Console.WriteLine($"URI: {uri}");
  33. string json = JsonSerializer.Serialize(new { token, fcmToken });
  34. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  35. HttpClient _httpClient = new HttpClient();
  36. PutAppVersionInHeader(_httpClient);
  37. HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
  38. if (response.IsSuccessStatusCode)
  39. {
  40. var options = new JsonSerializerOptions
  41. {
  42. PropertyNameCaseInsensitive = true
  43. };
  44. var responseData = await response.Content.ReadAsStringAsync();
  45. validateTokenResponseDto = JsonSerializer.Deserialize<ValidateTokenResponseDto>(responseData, options);
  46. }
  47. return validateTokenResponseDto;
  48. }
  49. public async Task<LoginResponseDto> Login(LoginRequestDto loginRequestDto)
  50. {
  51. LoginResponseDto loginResponseDto = new LoginResponseDto();
  52. try
  53. {
  54. Uri uri = new Uri(string.Format(BASE_URL + "/Auth/Login", string.Empty));
  55. Console.WriteLine($"URI: {uri}");
  56. string json = JsonSerializer.Serialize(loginRequestDto);
  57. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  58. HttpClient _httpClient = new HttpClient();
  59. PutAppVersionInHeader(_httpClient);
  60. HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
  61. var options = new JsonSerializerOptions
  62. {
  63. PropertyNameCaseInsensitive = true
  64. };
  65. var responseData = await response.Content.ReadAsStringAsync();
  66. loginResponseDto = JsonSerializer.Deserialize<LoginResponseDto>(responseData, options);
  67. if (response.IsSuccessStatusCode)
  68. {
  69. // DO Nothing
  70. }
  71. else if (response.StatusCode == HttpStatusCode.BadRequest)
  72. {
  73. //TODO
  74. return loginResponseDto;
  75. }
  76. else if (response.StatusCode == HttpStatusCode.Unauthorized)
  77. {
  78. //TODO
  79. return loginResponseDto;
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. throw ex;
  85. }
  86. return loginResponseDto;
  87. }
  88. public async Task<EftposLoginResponse> EftposLogin(EftposLoginRequest eftposLoginRequest)
  89. {
  90. EftposLoginResponse eftposLoginResponse = new EftposLoginResponse();
  91. Uri uri = new Uri(string.Format(BASE_URL_RYDO_API + "/v1/account/eftpos-login", string.Empty));
  92. Console.WriteLine($"URI: {uri}");
  93. string json = JsonSerializer.Serialize(eftposLoginRequest);
  94. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  95. HttpClient _httpClient = new HttpClient();
  96. PutAppVersionInHeader(_httpClient);
  97. HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
  98. if (response.IsSuccessStatusCode)
  99. {
  100. var options = new JsonSerializerOptions
  101. {
  102. PropertyNameCaseInsensitive = true
  103. };
  104. var responseData = await response.Content.ReadAsStringAsync();
  105. eftposLoginResponse = JsonSerializer.Deserialize<EftposLoginResponse>(responseData, options);
  106. }
  107. return eftposLoginResponse;
  108. }
  109. public async Task<UnreadCountResponseDto> GetUnreadNotificationCount(string appToken)
  110. {
  111. UnreadCountResponseDto unreadCountResponse = new UnreadCountResponseDto();
  112. var unreadNotificationCount = 0;
  113. Uri uri = new Uri($"{BASE_URL}/Notifications/UnreadCount?token={appToken}");
  114. Console.WriteLine($"URI: {uri}");
  115. HttpClient _httpClient = new HttpClient();
  116. PutAppVersionInHeader(_httpClient);
  117. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  118. if (response.IsSuccessStatusCode)
  119. {
  120. var options = new JsonSerializerOptions
  121. {
  122. PropertyNameCaseInsensitive = true
  123. };
  124. var responseData = await response.Content.ReadAsStringAsync();
  125. unreadNotificationCount = JsonSerializer.Deserialize<int>(responseData, options);
  126. unreadCountResponse.StatusCode = Constant.SUCCESS_CODE;
  127. unreadCountResponse.UnreadNotificationCount = unreadNotificationCount;
  128. }
  129. else
  130. {
  131. if (response.StatusCode == HttpStatusCode.Unauthorized)
  132. {
  133. unreadCountResponse.StatusCode = Constant.UNAUTHORIZED_CODE;
  134. unreadCountResponse.UnreadNotificationCount = unreadNotificationCount;
  135. }
  136. else
  137. {
  138. unreadCountResponse.StatusCode = Constant.BADREQUEST_CODE;
  139. unreadCountResponse.UnreadNotificationCount = unreadNotificationCount;
  140. }
  141. }
  142. return unreadCountResponse;
  143. }
  144. public async Task<List<Guid>> GetBookingAvailableCount(string accessToken, string driverId, double lat, double lng)
  145. {
  146. List<Guid> bookingIDs = null;
  147. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverId}/available?latitude={lat}&longitude={lng}");
  148. Console.WriteLine($"URI: {uri}");
  149. HttpClient _httpClient = new HttpClient();
  150. PutAppVersionInHeader(_httpClient);
  151. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  152. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  153. if (response.IsSuccessStatusCode)
  154. {
  155. var responseData = await response.Content.ReadAsStringAsync();
  156. List<BookingDto> bookings = JsonSerializer.Deserialize<List<BookingDto>>(responseData);
  157. if (bookings != null)
  158. {
  159. bookingIDs = new List<Guid>();
  160. foreach (BookingDto booking in bookings) { bookingIDs.Add(booking.BookingId); }
  161. }
  162. }
  163. return bookingIDs;
  164. }
  165. public async Task<List<CouponDto>> GetCoupons(string appToken)
  166. {
  167. List<CouponDto> coupons = new List<CouponDto>();
  168. Uri uri = new Uri(string.Format(BASE_URL + "/Coupons?token=" + appToken, string.Empty));
  169. Console.WriteLine($"URI: {uri}");
  170. HttpClient _httpClient = new HttpClient();
  171. PutAppVersionInHeader(_httpClient);
  172. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  173. if (response.IsSuccessStatusCode)
  174. {
  175. var options = new JsonSerializerOptions
  176. {
  177. PropertyNameCaseInsensitive = true
  178. };
  179. var responseData = await response.Content.ReadAsStringAsync();
  180. coupons = JsonSerializer.Deserialize<List<CouponDto>>(responseData, options);
  181. }
  182. else if (response.StatusCode == HttpStatusCode.BadRequest)
  183. {
  184. //TODO
  185. }
  186. else if (response.StatusCode == HttpStatusCode.Unauthorized)
  187. {
  188. //TODO
  189. }
  190. return coupons;
  191. }
  192. public async Task<List<CouponHistoryDto>> GetCouponsHistory(string appToken)
  193. {
  194. List<CouponHistoryDto> couponsHistory = new List<CouponHistoryDto>();
  195. Uri uri = new Uri(string.Format(BASE_URL + "/Coupons/History?token=" + appToken, string.Empty));
  196. Console.WriteLine($"URI: {uri}");
  197. HttpClient _httpClient = new HttpClient();
  198. PutAppVersionInHeader(_httpClient);
  199. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  200. if (response.IsSuccessStatusCode)
  201. {
  202. var options = new JsonSerializerOptions
  203. {
  204. PropertyNameCaseInsensitive = true
  205. };
  206. var responseData = await response.Content.ReadAsStringAsync();
  207. couponsHistory = JsonSerializer.Deserialize<List<CouponHistoryDto>>(responseData, options);
  208. }
  209. else if (response.StatusCode == HttpStatusCode.BadRequest)
  210. {
  211. //TODO
  212. }
  213. else if (response.StatusCode == HttpStatusCode.Unauthorized)
  214. {
  215. //TODO
  216. }
  217. return couponsHistory;
  218. }
  219. public async Task<List<NotificationDto>> GetNotifications(string appToken)
  220. {
  221. List<NotificationDto> notifications = new List<NotificationDto>();
  222. try
  223. {
  224. Uri uri = new Uri(string.Format(BASE_URL + "/Notifications?token=" + appToken, string.Empty));
  225. Console.WriteLine($"URI: {uri}");
  226. HttpClient _httpClient = new HttpClient();
  227. PutAppVersionInHeader(_httpClient);
  228. HttpResponseMessage respose = await _httpClient.GetAsync(uri);
  229. if (respose != null)
  230. {
  231. var options = new JsonSerializerOptions
  232. {
  233. PropertyNameCaseInsensitive = true
  234. };
  235. var responseData = await respose.Content.ReadAsStringAsync();
  236. notifications = JsonSerializer.Deserialize<List<NotificationDto>>(responseData, options);
  237. }
  238. }
  239. catch (Exception ex)
  240. {
  241. throw ex;
  242. }
  243. return notifications;
  244. }
  245. public async Task<bool> MarkNotificationAsViewed(string appToken, string notificationId)
  246. {
  247. Uri uri = new Uri($"{BASE_URL}/Notifications/NotificationViewed/{notificationId}?token={appToken}");
  248. Console.WriteLine($"URI: {uri}");
  249. HttpClient _httpClient = new HttpClient();
  250. PutAppVersionInHeader(_httpClient);
  251. var response = await _httpClient.PutAsync(uri, null);
  252. return response.IsSuccessStatusCode;
  253. }
  254. public async Task<List<BookingDto>> GetBookings(string accessToken, Guid driverId, double lat, double lng)
  255. {
  256. List<BookingDto> bookings = new List<BookingDto>();
  257. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverId}/available?latitude={lat}&longitude={lng}");
  258. Debug.WriteLine(uri);
  259. HttpClient _httpClient = new HttpClient();
  260. PutAppVersionInHeader(_httpClient);
  261. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  262. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  263. if (response.IsSuccessStatusCode)
  264. {
  265. var responseData = await response.Content.ReadAsStringAsync();
  266. bookings = JsonSerializer.Deserialize<List<BookingDto>>(responseData);
  267. //if (bookings.Count <= 0)
  268. //{
  269. // uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverId}/available?future_bookings=1");
  270. // _httpClient = new HttpClient();
  271. // _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  272. // response = await _httpClient.GetAsync(uri);
  273. // if (response.IsSuccessStatusCode)
  274. // {
  275. // var featureResponseData = await response.Content.ReadAsStringAsync();
  276. // bookings = JsonSerializer.Deserialize<List<BookingDto>>(featureResponseData);
  277. // }
  278. //}
  279. }
  280. bookings = bookings.OrderBy(x => x.FormmattedPickUpDateTime).ToList();
  281. return await Task.FromResult(bookings);
  282. }
  283. public async Task<AcceptDeclineBookingResponse> AcceptBooking(AcceptDeclineBookingRequest acceptBookingRequest, string accessToken, string bookingId)
  284. {
  285. AcceptDeclineBookingResponse acceptBookingResponse = new AcceptDeclineBookingResponse();
  286. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/accept");
  287. Console.WriteLine($"URI: {uri}");
  288. string json = JsonSerializer.Serialize(acceptBookingRequest);
  289. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  290. HttpClient _httpClient = new HttpClient();
  291. PutAppVersionInHeader(_httpClient);
  292. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  293. HttpResponseMessage response = await _httpClient.PutAsync(uri, content);
  294. if (response.IsSuccessStatusCode)
  295. {
  296. var options = new JsonSerializerOptions
  297. {
  298. PropertyNameCaseInsensitive = true
  299. };
  300. var responseData = await response.Content.ReadAsStringAsync();
  301. acceptBookingResponse = JsonSerializer.Deserialize<AcceptDeclineBookingResponse>(responseData, options);
  302. }
  303. acceptBookingResponse.StatusCode = (int)response.StatusCode;
  304. acceptBookingResponse.Message = (string)response.ReasonPhrase;
  305. return acceptBookingResponse;
  306. }
  307. public async Task<AcceptDeclineBookingResponse> DeclineBooking(AcceptDeclineBookingRequest declineBookingRequest, string accessToken, string bookingId)
  308. {
  309. AcceptDeclineBookingResponse declineBookingResponse = new AcceptDeclineBookingResponse();
  310. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/decline");
  311. Console.WriteLine($"URI: {uri}");
  312. string json = JsonSerializer.Serialize(declineBookingRequest);
  313. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  314. HttpClient _httpClient = new HttpClient();
  315. PutAppVersionInHeader(_httpClient);
  316. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  317. HttpResponseMessage response = await _httpClient.PutAsync(uri, content);
  318. declineBookingResponse.StatusCode = (int)response.StatusCode;
  319. declineBookingResponse.Message = (string)response.ReasonPhrase;
  320. return declineBookingResponse;
  321. }
  322. public async Task<int> SendDriverLocation(string appToken, LocationUpdateRequestDto locationUpdateRequestDto)
  323. {
  324. Uri uri = new Uri($"{BASE_URL}/DriverAssistantApp/UpdateLocation?token={appToken}");
  325. Console.WriteLine($"URI: {uri}");
  326. string json = JsonSerializer.Serialize(locationUpdateRequestDto);
  327. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  328. HttpClient _httpClient = new HttpClient();
  329. PutAppVersionInHeader(_httpClient);
  330. var response = await _httpClient.PutAsync(uri, content);
  331. return (int)response.StatusCode;
  332. }
  333. public async Task<int> SendDriverLocationTablet(LocationUpdateRequestDto locationUpdateRequestDto)
  334. {
  335. Uri uri = new Uri($"{BASE_URL}/DriverAssistantApp/UpdateLocationTablet");
  336. Console.WriteLine($"URI: {uri}");
  337. string json = JsonSerializer.Serialize(locationUpdateRequestDto);
  338. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  339. HttpClient _httpClient = new HttpClient();
  340. PutAppVersionInHeader(_httpClient);
  341. var response = await _httpClient.PutAsync(uri, content);
  342. return (int)response.StatusCode;
  343. }
  344. public async Task<bool> UpdateSilentModeSetting(string appToken, SilentModeSettingRequest request)
  345. {
  346. Uri uri = new Uri($"{BASE_URL}/DriverAssistantApp/UpdateDriverAppSilentModeSetting?token={appToken}");
  347. string json = JsonSerializer.Serialize(request);
  348. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  349. HttpClient _httpClient = new HttpClient();
  350. PutAppVersionInHeader(_httpClient);
  351. var response = await _httpClient.PutAsync(uri, content);
  352. return response.IsSuccessStatusCode;
  353. }
  354. public async Task<List<BookingDto>> GetAcceptedFutureBookings(string accessToken, Guid driverId)
  355. {
  356. List<BookingDto> bookings = new List<BookingDto>();
  357. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverId}/accepted");
  358. Debug.WriteLine(uri);
  359. HttpClient _httpClient = new HttpClient();
  360. PutAppVersionInHeader(_httpClient);
  361. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  362. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  363. if (response.IsSuccessStatusCode)
  364. {
  365. var responseData = await response.Content.ReadAsStringAsync();
  366. bookings = JsonSerializer.Deserialize<List<BookingDto>>(responseData);
  367. }
  368. return await Task.FromResult(bookings);
  369. }
  370. public async Task<BookingDto> GetBookingDetails(string accessToken, Guid bookingId)
  371. {
  372. BookingDto booking = new BookingDto();
  373. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/details");
  374. Debug.WriteLine(uri);
  375. HttpClient _httpClient = new HttpClient();
  376. PutAppVersionInHeader(_httpClient);
  377. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  378. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  379. if (response.IsSuccessStatusCode)
  380. {
  381. var responseData = await response.Content.ReadAsStringAsync();
  382. booking = JsonSerializer.Deserialize<BookingDto>(responseData);
  383. }
  384. return await Task.FromResult(booking);
  385. }
  386. public async Task<BookingDto> GetAcceptedOnDemandBookingForDriver(string accessToken, Guid driverId)
  387. {
  388. List<BookingDto> booking = new List<BookingDto>();
  389. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverId}/accepted");
  390. HttpClient _httpClient = new HttpClient();
  391. PutAppVersionInHeader(_httpClient);
  392. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  393. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  394. if (response.IsSuccessStatusCode)
  395. {
  396. var responseData = await response.Content.ReadAsStringAsync();
  397. booking = JsonSerializer.Deserialize<List<BookingDto>>(responseData);
  398. }
  399. // there can be only on accepted on demand booking so the below result will either be the only entry or null
  400. return await Task.FromResult(booking.FirstOrDefault());
  401. }
  402. public async Task<bool> UpdateProfile(string appToken, MultipartFormDataContent content)
  403. {
  404. Uri uri = new Uri($"{BASE_URL}/Driver/UpdateDriverDetails?token={appToken}");
  405. Debug.WriteLine(uri);
  406. HttpClient _httpClient = new HttpClient();
  407. PutAppVersionInHeader(_httpClient);
  408. HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
  409. return response.IsSuccessStatusCode;
  410. }
  411. public async Task<bool> GenerateOtp(string mobileNumber)
  412. {
  413. Uri uri = new Uri($"{BASE_URL}/Auth/GenerateOtp?mobileNumber={mobileNumber}");
  414. Debug.WriteLine(uri);
  415. HttpClient _httpClient = new HttpClient();
  416. PutAppVersionInHeader(_httpClient);
  417. HttpResponseMessage response = await _httpClient.PostAsync(uri, null);
  418. return response.IsSuccessStatusCode;
  419. }
  420. public async Task<bool> VerifyOtp(string mobileNumber, string otp)
  421. {
  422. var isOtpValid = false;
  423. Uri uri = new Uri($"{BASE_URL}/Auth/VerifyOtp");
  424. Console.WriteLine($"URI: {uri}");
  425. string json = JsonSerializer.Serialize(new { mobileNumber, otp });
  426. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  427. HttpClient _httpClient = new HttpClient();
  428. PutAppVersionInHeader(_httpClient);
  429. HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
  430. if (response.IsSuccessStatusCode)
  431. {
  432. var responseData = await response.Content.ReadAsStringAsync();
  433. isOtpValid = bool.Parse(responseData);
  434. }
  435. return isOtpValid;
  436. }
  437. public async Task<bool> UpdateDriverPin(string mobileNumber, int pin)
  438. {
  439. Uri uri = new Uri($"{BASE_URL}/Auth/UpdateDriverPin");
  440. Debug.WriteLine(uri);
  441. string json = JsonSerializer.Serialize(new { mobileNumber, pin });
  442. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  443. HttpClient _httpClient = new HttpClient();
  444. PutAppVersionInHeader(_httpClient);
  445. HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
  446. return response.IsSuccessStatusCode;
  447. }
  448. public async Task<string> CouponScan(string appToken, string couponText)
  449. {
  450. Uri uri = new Uri($"{BASE_URL}/Driver/CouponScan?token={appToken}");
  451. string json = JsonSerializer.Serialize(new { couponText });
  452. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  453. HttpClient _httpClient = new HttpClient();
  454. PutAppVersionInHeader(_httpClient);
  455. HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
  456. var status = await response.Content.ReadAsStringAsync();
  457. return status.ToString();
  458. }
  459. public async Task<int> VoucherScanedCount(string appToken, DateTime reportingDate)
  460. {
  461. var voucherScanedCount = 0;
  462. Uri uri = new Uri($"{BASE_URL}/Coupons/VouchersScannedCount?token={appToken}");
  463. string json = JsonSerializer.Serialize(new { reportingDate });
  464. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  465. HttpClient _httpClient = new HttpClient();
  466. PutAppVersionInHeader(_httpClient);
  467. HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
  468. if (response.IsSuccessStatusCode)
  469. {
  470. var options = new JsonSerializerOptions
  471. {
  472. PropertyNameCaseInsensitive = true
  473. };
  474. var responseData = await response.Content.ReadAsStringAsync();
  475. voucherScanedCount = JsonSerializer.Deserialize<int>(responseData, options);
  476. }
  477. return voucherScanedCount;
  478. }
  479. public async Task<bool> LogoutDriverApp(string appToken, double lastLat, double lastLng)
  480. {
  481. Uri uri = new Uri($"{BASE_URL}/Auth/Logout?token={appToken}&lastLat={lastLat}&lastLng={lastLng}");
  482. string json = JsonSerializer.Serialize(new { });
  483. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  484. HttpClient _httpClient = new HttpClient();
  485. PutAppVersionInHeader(_httpClient);
  486. var response = await _httpClient.PostAsync(uri, content);
  487. return response.IsSuccessStatusCode;
  488. }
  489. public async Task<bool> DeclineFutureBooking(string accessToken, String bookingId)
  490. {
  491. bool result = false;
  492. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/release");
  493. HttpClient _httpClient = new HttpClient();
  494. PutAppVersionInHeader(_httpClient);
  495. StringContent content = new StringContent("", Encoding.UTF8, "application/json");
  496. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  497. HttpResponseMessage response = await _httpClient.PutAsync(uri, content);
  498. if (response.IsSuccessStatusCode)
  499. {
  500. result = true;
  501. }
  502. return result;
  503. }
  504. public async Task<bool> CreateLightDriver(CreateLightDriverRequest createLightDriverRequest)
  505. {
  506. bool result = false;
  507. try
  508. {
  509. Uri uri = new Uri(string.Format(BASE_URL + "/Auth/CreateLightDriver", string.Empty));
  510. Console.WriteLine($"URI: {uri}");
  511. string json = JsonSerializer.Serialize(createLightDriverRequest);
  512. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  513. HttpClient _httpClient = new HttpClient();
  514. PutAppVersionInHeader(_httpClient);
  515. HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
  516. if (response.StatusCode == HttpStatusCode.OK)
  517. {
  518. result= true;
  519. }
  520. else if (response.StatusCode == HttpStatusCode.BadRequest)
  521. {
  522. //TODO
  523. result= false;
  524. }
  525. }
  526. catch (Exception ex)
  527. {
  528. result = false;
  529. }
  530. return result;
  531. }
  532. public async Task<LocationVoucherDto> GetLocationVoucherByLocationID(string appToken, int issuedFromLocationID)
  533. {
  534. LocationVoucherDto locationVoucher = new LocationVoucherDto();
  535. Uri uri = new Uri(string.Format(BASE_URL + "/Coupons/GetLocationVoucherByLocationID?token=" + appToken+ "&issuedFromLocationID=" + issuedFromLocationID, string.Empty));
  536. Console.WriteLine($"URI: {uri}");
  537. HttpClient _httpClient = new HttpClient();
  538. PutAppVersionInHeader(_httpClient);
  539. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  540. if (response.IsSuccessStatusCode)
  541. {
  542. var options = new JsonSerializerOptions
  543. {
  544. PropertyNameCaseInsensitive = true
  545. };
  546. var responseData = await response.Content.ReadAsStringAsync();
  547. locationVoucher = JsonSerializer.Deserialize<LocationVoucherDto>(responseData, options);
  548. }
  549. else if (response.StatusCode == HttpStatusCode.BadRequest)
  550. {
  551. //TODO
  552. }
  553. else if (response.StatusCode == HttpStatusCode.Unauthorized)
  554. {
  555. //TODO
  556. }
  557. return locationVoucher;
  558. }
  559. public async Task<bool> ValidateAdminPassword(string adminPassword)
  560. {
  561. var isValidAdminPassword = false;
  562. Uri uri = new Uri(string.Format(BASE_URL + "/Auth/ValidateAdminPassword?adminPassword=" + adminPassword));
  563. Console.WriteLine($"URI: {uri}");
  564. HttpClient _httpClient = new HttpClient();
  565. PutAppVersionInHeader(_httpClient);
  566. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  567. if (response.StatusCode == HttpStatusCode.OK)
  568. {
  569. isValidAdminPassword = true;
  570. }
  571. else if (response.StatusCode == HttpStatusCode.BadRequest)
  572. {
  573. isValidAdminPassword = false;
  574. }
  575. return isValidAdminPassword;
  576. }
  577. public async Task<bool> ValidateTaxiNumberInstallation(string taxiNumber)
  578. {
  579. var isValidAdminPassword = false;
  580. Uri uri = new Uri(string.Format(BASE_URL + "/DriverAssistantApp/ValidateTaxiNumberInstallation?taxiNumber=" + taxiNumber));
  581. Console.WriteLine($"URI: {uri}");
  582. HttpClient _httpClient = new HttpClient();
  583. PutAppVersionInHeader(_httpClient);
  584. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  585. if (response.StatusCode == HttpStatusCode.OK)
  586. {
  587. isValidAdminPassword = true;
  588. }
  589. else if (response.StatusCode == HttpStatusCode.BadRequest)
  590. {
  591. isValidAdminPassword = false;
  592. }
  593. return isValidAdminPassword;
  594. }
  595. public async Task<StartRideResponse> StartRiding(StartRideRequest startRideRequest, string accessToken, string bookingId)
  596. {
  597. StartRideResponse startRideResponse = new StartRideResponse();
  598. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/start-ride");
  599. Console.WriteLine($"URI: {uri}");
  600. string json = JsonSerializer.Serialize(startRideRequest);
  601. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  602. HttpClient _httpClient = new HttpClient();
  603. PutAppVersionInHeader(_httpClient);
  604. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  605. HttpResponseMessage response = await _httpClient.PutAsync(uri, content);
  606. if (response.IsSuccessStatusCode)
  607. {
  608. var options = new JsonSerializerOptions
  609. {
  610. PropertyNameCaseInsensitive = true
  611. };
  612. var responseData = await response.Content.ReadAsStringAsync();
  613. startRideResponse = JsonSerializer.Deserialize<StartRideResponse>(responseData, options);
  614. }
  615. startRideResponse.StatusCode = (int)response.StatusCode;
  616. startRideResponse.Message = (string)response.ReasonPhrase;
  617. return startRideResponse;
  618. }
  619. public async Task<ApiResponseDto> SendMessage(MessageRequest messageRequest, string accessToken, string bookingId)
  620. {
  621. ApiResponseDto apiResponseDto = new ApiResponseDto();
  622. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/message");
  623. Console.WriteLine($"URI: {uri}");
  624. string json = JsonSerializer.Serialize(messageRequest);
  625. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  626. HttpClient _httpClient = new HttpClient();
  627. PutAppVersionInHeader(_httpClient);
  628. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  629. var response = await _httpClient.PostAsync(uri, content);
  630. apiResponseDto.StatusCode = (int)response.StatusCode;
  631. apiResponseDto.Message = (string)response.ReasonPhrase;
  632. return apiResponseDto;
  633. }
  634. public async Task<ApiResponseDto> ReleaseBooking(string accessToken, string bookingId)
  635. {
  636. ApiResponseDto apiResponseDto = new ApiResponseDto();
  637. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/release");
  638. Console.WriteLine($"URI: {uri}");
  639. string json = JsonSerializer.Serialize(new { });
  640. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  641. HttpClient _httpClient = new HttpClient();
  642. PutAppVersionInHeader(_httpClient);
  643. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  644. var response = await _httpClient.PutAsync(uri, content);
  645. apiResponseDto.StatusCode = (int)response.StatusCode;
  646. apiResponseDto.Message = (string)response.ReasonPhrase;
  647. return apiResponseDto;
  648. }
  649. public async Task<ApiResponseDto> NoShowBooking(string accessToken, string bookingId)
  650. {
  651. ApiResponseDto apiResponseDto = new ApiResponseDto();
  652. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/no-show");
  653. Console.WriteLine($"URI: {uri}");
  654. string json = JsonSerializer.Serialize(new { });
  655. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  656. HttpClient _httpClient = new HttpClient();
  657. PutAppVersionInHeader(_httpClient);
  658. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  659. var response = await _httpClient.PutAsync(uri, content);
  660. apiResponseDto.StatusCode = (int)response.StatusCode;
  661. apiResponseDto.Message = (string)response.ReasonPhrase;
  662. return apiResponseDto;
  663. }
  664. public async Task<int> NotifyStop(int stopNumber, string accessToken, string bookingId)
  665. {
  666. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/notify-stop?stop_number={stopNumber}");
  667. Console.WriteLine($"URI: {uri}");
  668. string json = JsonSerializer.Serialize(new { });
  669. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  670. HttpClient _httpClient = new HttpClient();
  671. PutAppVersionInHeader(_httpClient);
  672. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  673. HttpResponseMessage response = await _httpClient.PutAsync(uri, content);
  674. return (int)response.StatusCode;
  675. }
  676. public async Task<ApiResponseDto> EndRiding(EndRideRequestDto endRideRequestDto, string accessToken, string bookingId)
  677. {
  678. ApiResponseDto apiResponseDto = new ApiResponseDto();
  679. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/end-ride");
  680. Console.WriteLine($"URI: {uri}");
  681. string json = JsonSerializer.Serialize(endRideRequestDto);
  682. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  683. HttpClient _httpClient = new HttpClient();
  684. PutAppVersionInHeader(_httpClient);
  685. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  686. var response = await _httpClient.PutAsync(uri, content);
  687. apiResponseDto.StatusCode = (int)response.StatusCode;
  688. apiResponseDto.Message = (string)response.ReasonPhrase;
  689. return apiResponseDto;
  690. }
  691. public async Task<ApiResponseDto> MakePaymentAtTerminal(string bookingId, string driverId, int amount)
  692. {
  693. ApiResponseDto apiResponseDto = new ApiResponseDto();
  694. Uri uri = new Uri(string.Format(BASE_URL + "/Terminal/PayAtTerminal?bookingID=" + bookingId + "&driverID=" + driverId + "&amount=" + amount));
  695. Console.WriteLine($"URI: {uri}");
  696. string json = JsonSerializer.Serialize(new { });
  697. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  698. HttpClient _httpClient = new HttpClient();
  699. PutAppVersionInHeader(_httpClient);
  700. var response = await _httpClient.PutAsync(uri, content);
  701. apiResponseDto.StatusCode = (int)response.StatusCode;
  702. apiResponseDto.Message = (string)response.ReasonPhrase;
  703. return apiResponseDto;
  704. }
  705. public async Task<bool> CloseAccountDriverApp(string appToken)
  706. {
  707. Uri uri = new Uri($"{BASE_URL}/Driver/CloseAccount?token={appToken}");
  708. string json = JsonSerializer.Serialize(new { });
  709. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  710. HttpClient _httpClient = new HttpClient();
  711. PutAppVersionInHeader(_httpClient);
  712. var response = await _httpClient.PutAsync(uri, content);
  713. return response.IsSuccessStatusCode;
  714. }
  715. public async Task<string> UpdateBookingStatus(string appToken, int statusFlag, bool isMetered)
  716. {
  717. Uri uri = new Uri(string.Format(BASE_URL + $"/DriverAssistantApp/MeterTripStatus?token={appToken}&statusFlag={statusFlag}&isMetered={isMetered}"));
  718. string json = JsonSerializer.Serialize(new { });
  719. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  720. HttpClient _httpClient = new HttpClient();
  721. PutAppVersionInHeader(_httpClient);
  722. var response = await _httpClient.PutAsync(uri, content);
  723. var suburbName = (response.StatusCode == HttpStatusCode.OK) ? await response.Content.ReadAsStringAsync() : String.Empty;
  724. return suburbName.ToString();
  725. }
  726. public async Task<bool> DriverDistress(string appToken, double lat, double lng)
  727. {
  728. bool result = false;
  729. Uri uri = new Uri(string.Format(BASE_URL + $"/DriverAssistantApp/DriverDistress?token={appToken}&lat={lat}&lng={lng}"));
  730. string json = JsonSerializer.Serialize(new { });
  731. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  732. HttpClient _httpClient = new HttpClient();
  733. PutAppVersionInHeader(_httpClient);
  734. var response = await _httpClient.PutAsync(uri, content);
  735. if (response.StatusCode == HttpStatusCode.OK)
  736. {
  737. result = true;
  738. }
  739. return result;
  740. }
  741. public async Task<bool> RequestPayment(string appToken, int amount)
  742. {
  743. Uri uri = new Uri(string.Format(BASE_URL + "/DriverAssistantApp/RequestPayment?token=" + appToken + "&amount=" + amount));
  744. string json = JsonSerializer.Serialize(new { });
  745. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  746. HttpClient _httpClient = new HttpClient();
  747. PutAppVersionInHeader(_httpClient);
  748. var response = await _httpClient.PutAsync(uri, content);
  749. return response.IsSuccessStatusCode;
  750. }
  751. public async Task<List<ImeiDto>> GetAvailableImeiNumbers(string enteredValue)
  752. {
  753. List<ImeiDto> imeiNumers = null;
  754. Uri uri = new Uri($"{BASE_URL}/TabletDevice/UninstalledImeis?enteredValue={enteredValue}");
  755. HttpClient _httpClient = new HttpClient();
  756. PutAppVersionInHeader(_httpClient);
  757. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  758. if (response.IsSuccessStatusCode)
  759. {
  760. var options = new JsonSerializerOptions
  761. {
  762. PropertyNameCaseInsensitive = true
  763. };
  764. var responseData = await response.Content.ReadAsStringAsync();
  765. if (responseData != string.Empty)
  766. {
  767. imeiNumers = JsonSerializer.Deserialize<List<ImeiDto>>(responseData,options);
  768. }
  769. }
  770. return imeiNumers;
  771. }
  772. // now done on logon
  773. //public async Task<bool> CompleteInstallation(string imeiValue)
  774. //{
  775. // bool result = false;
  776. // Uri uri = new Uri($"{BASE_URL}/TabletDevice/CompleteTabletInstall?imei={imeiValue}");
  777. // string json = JsonSerializer.Serialize(new { });
  778. // StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  779. // HttpClient _httpClient = new HttpClient();
  780. // var response = await _httpClient.PutAsync(uri, content);
  781. // if (response.IsSuccessStatusCode)
  782. // {
  783. // // need to handle a false in content result which means some other device has already been installed in the selected taxi
  784. // result = true;
  785. // }
  786. // return result;
  787. //}
  788. public async Task<List<TripsBookingResponse>> GetTripDetails(string appToken)
  789. {
  790. List<TripsBookingResponse> tripsBookingResponses = new List<TripsBookingResponse>();
  791. Uri uri = new Uri(string.Format(BASE_URL + "/DriverAssistantApp/Trips?token=" + appToken));
  792. HttpClient _httpClient = new HttpClient();
  793. PutAppVersionInHeader(_httpClient);
  794. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  795. if (response.IsSuccessStatusCode)
  796. {
  797. var options = new JsonSerializerOptions
  798. {
  799. PropertyNameCaseInsensitive = true
  800. };
  801. var responseData = await response.Content.ReadAsStringAsync();
  802. tripsBookingResponses = JsonSerializer.Deserialize<List<TripsBookingResponse>>(responseData, options);
  803. }
  804. return tripsBookingResponses;
  805. }
  806. public async Task<AccountBalanceDto> GetLevyBalance(string appToken)
  807. {
  808. AccountBalanceDto accountBalanceDto = new AccountBalanceDto();
  809. Uri uri = new Uri(string.Format(BASE_URL + "/Driver/AccountBalance?token=" + appToken));
  810. HttpClient _httpClient = new HttpClient();
  811. PutAppVersionInHeader(_httpClient);
  812. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  813. if (response.IsSuccessStatusCode)
  814. {
  815. var options = new JsonSerializerOptions
  816. {
  817. PropertyNameCaseInsensitive = true
  818. };
  819. var responseData = await response.Content.ReadAsStringAsync();
  820. accountBalanceDto = JsonSerializer.Deserialize<AccountBalanceDto>(responseData, options);
  821. }
  822. return accountBalanceDto;
  823. }
  824. public async Task<DriverRatingResponse> GetDriverRatings(string accessToken, string driverId, string phoneNumber)
  825. {
  826. DriverRatingResponse driverRatingResponse = new DriverRatingResponse();
  827. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/drivers?id={driverId}&phone_number={phoneNumber}");
  828. HttpClient _httpClient = new HttpClient();
  829. PutAppVersionInHeader(_httpClient);
  830. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  831. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  832. if (response.IsSuccessStatusCode)
  833. {
  834. var options = new JsonSerializerOptions
  835. {
  836. PropertyNameCaseInsensitive = true
  837. };
  838. var responseData = await response.Content.ReadAsStringAsync();
  839. driverRatingResponse = JsonSerializer.Deserialize<DriverRatingResponse>(responseData, options);
  840. }
  841. return driverRatingResponse;
  842. }
  843. public async Task<List<ShiftResponseDto>> GetShiftDetails(string appToken)
  844. {
  845. List<ShiftResponseDto> shiftResponses = new List<ShiftResponseDto>();
  846. Uri uri = new Uri(string.Format(BASE_URL + "/DriverAssistantApp/Shifts?token=" + appToken));
  847. HttpClient _httpClient = new HttpClient();
  848. PutAppVersionInHeader(_httpClient);
  849. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  850. if (response.IsSuccessStatusCode)
  851. {
  852. var options = new JsonSerializerOptions
  853. {
  854. PropertyNameCaseInsensitive = true
  855. };
  856. var responseData = await response.Content.ReadAsStringAsync();
  857. shiftResponses = JsonSerializer.Deserialize<List<ShiftResponseDto>>(responseData, options);
  858. }
  859. return shiftResponses;
  860. }
  861. public async Task<List<PlotResponseDto>> GetAvailablePlot(string accessToken, string driverId, double lat, double lng)
  862. {
  863. List<PlotResponseDto> plotResponses = new List<PlotResponseDto>();
  864. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/available-plot?driver_id={driverId}&lat={lat}&lng={lng}");
  865. HttpClient _httpClient = new HttpClient();
  866. PutAppVersionInHeader(_httpClient);
  867. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  868. HttpResponseMessage response = await _httpClient.GetAsync(uri);
  869. if (response.IsSuccessStatusCode)
  870. {
  871. var options = new JsonSerializerOptions
  872. {
  873. PropertyNameCaseInsensitive = true
  874. };
  875. var responseData = await response.Content.ReadAsStringAsync();
  876. plotResponses = JsonSerializer.Deserialize<List<PlotResponseDto>>(responseData, options);
  877. }
  878. return plotResponses;
  879. }
  880. public async Task<AvailablePlotResponseDto> GetPlottedDriverInformation(AvailablePlotRequestDto availablePlotRequest, string accessToken)
  881. {
  882. AvailablePlotResponseDto availablePlotResponse = new AvailablePlotResponseDto();
  883. Uri uri = new Uri(string.Format(BASE_URL_RYDO_API + "/v1/bookings/driver-plot", string.Empty));
  884. Console.WriteLine($"URI: {uri}");
  885. string json = JsonSerializer.Serialize(availablePlotRequest);
  886. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  887. HttpClient _httpClient = new HttpClient();
  888. PutAppVersionInHeader(_httpClient);
  889. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  890. HttpResponseMessage response = await _httpClient.PostAsync(uri, content);
  891. if (response.IsSuccessStatusCode)
  892. {
  893. var options = new JsonSerializerOptions
  894. {
  895. PropertyNameCaseInsensitive = true
  896. };
  897. var responseData = await response.Content.ReadAsStringAsync();
  898. availablePlotResponse = JsonSerializer.Deserialize<AvailablePlotResponseDto>(responseData, options);
  899. availablePlotResponse.apiResponseDto = new ApiResponseDto();
  900. availablePlotResponse.apiResponseDto.StatusCode = (int)response.StatusCode;
  901. availablePlotResponse.apiResponseDto.Message = string.Empty;
  902. }
  903. else if (response.StatusCode == HttpStatusCode.InternalServerError)
  904. {
  905. availablePlotResponse.apiResponseDto = new ApiResponseDto();
  906. availablePlotResponse.apiResponseDto.StatusCode = (int)response.StatusCode;
  907. availablePlotResponse.apiResponseDto.Message = (string)response.ReasonPhrase;
  908. }
  909. else
  910. {
  911. availablePlotResponse.apiResponseDto = new ApiResponseDto();
  912. availablePlotResponse.apiResponseDto.StatusCode = (int)response.StatusCode;
  913. availablePlotResponse.apiResponseDto.Message = "Unable to plot in this area";
  914. }
  915. return availablePlotResponse;
  916. }
  917. public async Task<int> RemoveDriverPlot(Guid driverID, string accessToken)
  918. {
  919. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{driverID}/driver-leave-plot");
  920. Console.WriteLine($"URI: {uri}");
  921. string json = JsonSerializer.Serialize(new { });
  922. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  923. HttpClient _httpClient = new HttpClient();
  924. PutAppVersionInHeader(_httpClient);
  925. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  926. HttpResponseMessage response = await _httpClient.PutAsync(uri, content);
  927. return (int)response.StatusCode;
  928. }
  929. public async Task<StartTripResponse> StartTripFutureBooking(StartTripRequest startTripRequest, string accessToken, string bookingId)
  930. {
  931. StartTripResponse startTripResponse = new StartTripResponse();
  932. Uri uri = new Uri($"{BASE_URL_RYDO_API}/v1/bookings/{bookingId}/head-to-pickup");
  933. Console.WriteLine($"URI: {uri}");
  934. string json = JsonSerializer.Serialize(startTripRequest);
  935. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  936. HttpClient _httpClient = new HttpClient();
  937. PutAppVersionInHeader(_httpClient);
  938. _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  939. HttpResponseMessage response = await _httpClient.PutAsync(uri, content);
  940. if (response.IsSuccessStatusCode)
  941. {
  942. var options = new JsonSerializerOptions
  943. {
  944. PropertyNameCaseInsensitive = true
  945. };
  946. var responseData = await response.Content.ReadAsStringAsync();
  947. startTripResponse = JsonSerializer.Deserialize<StartTripResponse>(responseData, options);
  948. }
  949. startTripResponse.ResponseStatusCode = (int)response.StatusCode;
  950. startTripResponse.Message = (string)response.ReasonPhrase;
  951. return startTripResponse;
  952. }
  953. public async Task<bool> DriverAppSelectedPermissions(string appToken, DriverAppSelectedPermissionsDto request)
  954. {
  955. Uri uri = new Uri($"{BASE_URL}/DriverAssistantApp/DriverAppSelectedPermissions?token={appToken}");
  956. string json = JsonSerializer.Serialize(request);
  957. StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
  958. HttpClient _httpClient = new HttpClient();
  959. PutAppVersionInHeader(_httpClient);
  960. var response = await _httpClient.PutAsync(uri, content);
  961. return response.IsSuccessStatusCode;
  962. }
  963. #endregion
  964. #region Utility
  965. private void PutAppVersionInHeader(HttpClient _httpClient)
  966. {
  967. string[] parts = AppInfo.Version.ToString().Split('.');
  968. string formattedString = parts.Select(p => int.Parse(p).ToString("D2")).Aggregate((p1, p2) => p1 + p2);
  969. _httpClient.DefaultRequestHeaders.Add("app-version", formattedString);
  970. }
  971. #endregion Utility
  972. }
  973. }