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.

105 lines
3.6 KiB

1 year ago
  1. using GMCabsDriverAssistant.Services;
  2. using GMCabsDriverAssistant.Utils;
  3. namespace GMCabsDriverAssistantSolution.Views;
  4. public partial class ScanDrivingLicencePage : ContentPage
  5. {
  6. //private FileResult drivingLicencePhoto;
  7. private string drivingLicencePhoto;
  8. private Stream _stream;
  9. private GMCabsDriverService _service;
  10. public ScanDrivingLicencePage()
  11. {
  12. InitializeComponent();
  13. _service = new GMCabsDriverService();
  14. }
  15. private void ScanDrivingLicence_Clicked(object sender, EventArgs e)
  16. {
  17. try
  18. {
  19. if (MediaPicker.IsCaptureSupported)
  20. {
  21. //string action = await DisplayActionSheet("Scan Driving licence?", "Cancel", null , "Capture Photo", "From Gallery");
  22. //if (action == "Cancel")
  23. //{
  24. // return;
  25. //}
  26. //drivingLicencePhoto = action == "Capture Photo"? await MediaPicker.CapturePhotoAsync() : await MediaPicker.PickPhotoAsync();
  27. //new ImageCropper()
  28. //{
  29. // PageTitle = "Crop Photo",
  30. // AspectRatioX = 3,
  31. // AspectRatioY = 2,
  32. // CropShape = ImageCropper.CropShapeType.Rectangle,
  33. // SelectSourceTitle = "Select source",
  34. // TakePhotoTitle = "Capture Photo",
  35. // PhotoLibraryTitle = "From Gallery",
  36. // Success = (imageFile) =>
  37. // {
  38. // Device.BeginInvokeOnMainThread(() =>
  39. // {
  40. // resultImage.Source = ImageSource.FromFile(imageFile);
  41. // if (resultImage.Source != null)
  42. // {
  43. // drivingLicencePhoto = imageFile;
  44. // BtnUpdateProfile.IsEnabled = true;
  45. // }
  46. // });
  47. // }
  48. //}.Show(this);
  49. //if (drivingLicencePhoto != null)
  50. //{
  51. // _stream = await drivingLicencePhoto.OpenReadAsync();
  52. // resultImage.Source = ImageSource.FromStream(() => _stream);
  53. // if (resultImage.Source != null)
  54. // {
  55. // BtnUpdateProfile.IsEnabled = true;
  56. // }
  57. //}
  58. }
  59. }
  60. catch (Exception ex) { }
  61. }
  62. private async void BtnUpdateProfile_Clicked(object sender, EventArgs e)
  63. {
  64. if (drivingLicencePhoto == null)
  65. {
  66. return;
  67. }
  68. string appToken = Preferences.Get(SecureStorageData.Token, "");
  69. var content = new MultipartFormDataContent();
  70. string[] res = drivingLicencePhoto.Split('/');
  71. if (res.Length > 0)
  72. {
  73. string fileName = res[res.Length - 1];
  74. content.Add(new StreamContent(System.IO.File.OpenRead(drivingLicencePhoto)), "files", fileName);
  75. var status = await _service.UpdateProfile(appToken, content);
  76. await DisplayAlert("Update Profile", status ? "Profile updated successful" : "Profile update failed", "OK");
  77. if (status)
  78. {
  79. await Shell.Current.GoToAsync("..");
  80. }
  81. else
  82. {
  83. BtnUpdateProfile.IsEnabled = false;
  84. resultImage.Source = null;
  85. }
  86. }
  87. }
  88. private async void BtnPageBack_Clicked(object sender, EventArgs e)
  89. {
  90. await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
  91. }
  92. }