private async void BtnConfirm_Clicked(object sender, EventArgs e)
        {
            await Navigation.PushPopupAsync(new HarbiSahaApp.AnimationPages.AnimationPopUpPage1_Waiting("Yükleniyor.."));

            imgStream = mainFile.GetStream();

            string userPhotoName = currentUser.Id.ToString() + "_pp";
            var    content       = new MultipartFormDataContent();

            content.Add(new StreamContent(mainFile.GetStream()), "FileName", mainFile.Path);
            //content.Add(new ImageSo)
            string message = await service.ChangeProfilePhoto(content, currentUser.Id);

            User toBeReturned = await service.GetSingleUser(currentUser.Id);

            currentUser.PhotoPath = toBeReturned.PhotoPath;
            App.Current.Properties["loggedUser"] = currentUser;
            await Navigation.PopPopupAsync();

            if (message == "Başarılı")
            {
                await DisplayAlert("Başarılı", "Profil fotoğrafınız gücellendi!", "Tamam");

                mainFile.Dispose();
            }
        }
        private async void EditIcon_Tabbed(object sender, EventArgs e)
        {
            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await DisplayAlert("Alert", "not supprored", "ok");
            }
            var mediaoptions = new Plugin.Media.Abstractions.PickMediaOptions()
            {
                PhotoSize = PhotoSize.Medium
            };

            selectedimgfile = await CrossMedia.Current.PickPhotoAsync(mediaoptions);

            if (selectedimgfile == null)
            {
                await DisplayAlert("error", "tryagain", "ok");
            }
            else
            {
                UserImage.Source = ImageSource.FromStream(() => selectedimgfile.GetStream());
                Stream stream    = selectedimgfile.GetStream();
                var    imagePath = await UserProfileViewModel.UploadImage(stream, selectedimgfile.Path);

                var userID = int.Parse(Application.Current.Properties["UserID"].ToString());
                User.Image = imagePath;

                User = await UserProfileViewModel.EditUser(User, User.ID);

                UserImage.Source = App.ServiceURL + User.Image;
            }
        }
Esempio n. 3
0
        public async Task OpenPhotoTaker()
        {
            try
            {
                ActivateSpinner();

                var rnd       = new Random();
                var rndEnding = rnd.Next(100, 9999);
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await _userDialogs.AlertAsync("It appears that no camera is available", "No Camera", "OK");

                    return;
                }
                var myfile = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    PhotoSize          = Plugin.Media.Abstractions.PhotoSize.Small,         //resizes the photo to 50% of the original
                    CompressionQuality = 92,                                                // Int from 0 to 100 to determine image compression level
                    DefaultCamera      = Plugin.Media.Abstractions.CameraDevice.Front,      // determine which camera to default to
                    Directory          = "CC Directors",
                    Name        = $"mybrulepic{rndEnding}",
                    SaveToAlbum = true,                                                     // this saves the photo to the camera roll
                                                                                            //if we need the public album path --> var aPpath = file.AlbumPath;
                                                                                            //if we need a private path --> var path = file.Path;
                    AllowCropping = false,
                });

                file = myfile;
                if (file == null)
                {
                    DeactivateSpinner();
                    return;
                }

                Debug.WriteLine("File Location: " + file.Path + "     <--- here");
                setImage = ImageSource.FromStream(() =>
                {
                    var stream      = file.GetStream();
                    var path        = file.Path;
                    var pathprivate = file.AlbumPath;
                    Debug.WriteLine(path.ToString());
                    Debug.WriteLine(pathprivate.ToString());
                    selectedImage = file.GetStream();

                    return(stream);
                });
                imageShowing = true;
                RaisePropertyChanged();

                WouldBruleLikeIt(file);
                DeactivateSpinner();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                DeactivateSpinner();
            }
        }
Esempio n. 4
0
        public async Task OpenPhotoSelecter()
        {
            try
            {
                ActivateSpinner();

                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await _userDialogs.AlertAsync("Permission was not granted to access camera roll or picking photos is not available on this device.", "Cannot Pick Photo", "OK");

                    return;
                }
                var myfile = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
                {
                    PhotoSize          = PhotoSize.Small,
                    CompressionQuality = 92,
                });

                file = myfile;
                if (file == null)
                {
                    DeactivateSpinner();
                    return;
                }
                string filePath = file.Path;
                string fileType = filePath.Substring(filePath.Length - 4);
                Debug.WriteLine($"****    {fileType}   *****");
                if (fileType == ".jpg" || fileType == ".png" || fileType == ".JPG" || fileType == ".PNG")
                {
                    setImage = ImageSource.FromStream(() =>
                    {
                        var stream      = file.GetStream();
                        var path        = file.Path;
                        var pathprivate = file.AlbumPath;
                        Debug.WriteLine(path);
                        Debug.WriteLine(pathprivate);
                        selectedImage = file.GetStream();

                        //file.Dispose();
                        return(stream);
                    });
                    imageShowing = true;
                    RaisePropertyChanged();

                    WouldBruleLikeIt(file);
                    DeactivateSpinner();
                }
                else
                {
                    await _userDialogs.AlertAsync("Unsupported file type.", "Error", "OK");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                DeactivateSpinner();
            }
        }
Esempio n. 5
0
        private async void TakePhoneBtn_Clicked(object sender, EventArgs e)
        {
            Plugin.Media.Abstractions.StoreCameraMediaOptions options = new Plugin.Media.Abstractions.StoreCameraMediaOptions()
            {
                SaveToAlbum   = false,
                DefaultCamera = CameraDevice.Front,
            };
            mediaFile = await CrossMedia.Current.TakePhotoAsync(options);

            CameraImage.Source = ImageSource.FromStream(() =>
            {
                return(mediaFile.GetStream());
            });
            _imageStream = mediaFile.GetStream();
        }
        async void BtnSubmit_Clicked(object sender, EventArgs e)
        {
            //Clicked is a boolean check to prevent the multiple method call
            if (!clicked)
            {
                clicked = true;
                if (!ReferenceEquals(_employeeModel, null))
                {
                    SubmitAttendance(_employeeModel).Wait();
                }
                else if (!ReferenceEquals(profileData, null))
                {
                    var isSettingOn = CrossSecureStorage.Current.GetValue("UploadManually", "");

                    if (isSettingOn.Equals("true"))
                    {
                        SubmitAttendance().Wait();
                    }
                    else
                    {
                        var    bytes     = StaticMethods.StreamToByte(profileData.GetStream());
                        string imageData = Convert.ToBase64String(bytes);
                        var    emp       = new List <tblEmployee>();
                        emp.Add(new tblEmployee
                        {
                            GpsLocation  = Lattitude.ToString() + "," + Longitude.ToString(),
                            ProfileImage = imageData,
                            EventCode    = EventCode,
                            JobCode      = JobCode,
                            UploadedTime = System.DateTime.Now.ToString("f"),
                            IsUploaded   = false
                        });
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            EmployeeService es = new EmployeeService();
                            await es.AddEmployees(emp);
                            StaticMethods.ShowToast("Attendance has been saved in Offline Mode");
                            App.Current.MainPage = new NavigationPage(new HomePage());
                        });
                    }
                }
                else
                {
                    clicked = false;
                    StaticMethods.ShowToast("Please upload picture.");
                }
            }
        }
Esempio n. 7
0
        public string SaveFotoFromAlbum(string caminhoImagem, Plugin.Media.Abstractions.MediaFile file)
        {
            string nomeArquivo;

            if (string.IsNullOrEmpty(caminhoImagem) || caminhoImagem.StartsWith("http"))
            {
                nomeArquivo = String.Format("{0:ddMMyyy_HHmm}", DateTime.Now) + ".jpg";
            }
            else
            {
                if (File.Exists(DependencyService.Get <IFotoLoadMediaPlugin>().GetPathToPhoto(caminhoImagem)))
                {
                    File.Delete(DependencyService.Get <IFotoLoadMediaPlugin>().GetPathToPhoto(caminhoImagem));
                }
                nomeArquivo = (caminhoImagem.LastIndexOf("/") > 0) ? caminhoImagem.Substring(caminhoImagem.LastIndexOf("/") + 1) : caminhoImagem;
            }

            var caminhoFotos = DependencyService.Get <IFotoLoadMediaPlugin>().GetDevicePathToPhoto();

            if (!Directory.Exists(caminhoFotos))
            {
                Directory.CreateDirectory(caminhoFotos);
            }

            string caminhoCompleto = Path.Combine(caminhoFotos, nomeArquivo);

            using (FileStream fileStream = new FileStream(caminhoCompleto, FileMode.Create))
            {
                file.GetStream().CopyTo(fileStream);
            }
            return(DependencyService.Get <IFotoLoadMediaPlugin>().SetPathToPhoto(caminhoCompleto));
        }
 public PagePrincipal(Plugin.Media.Abstractions.MediaFile Foto)
 {
     InitializeComponent();
     MinhaImagem.Source = ImageSource.FromStream(() =>
     {
         var stream = Foto.GetStream();
         Foto.Dispose();
         return(stream);
     });
     //testeDB.Text = App.DbPath;
     Detail = new PageHome();
     bt_home_Clicked(new object(), new EventArgs());
 }
Esempio n. 9
0
        // update avatar to sql server and mongodb.
        async void UpdateAvatar(Plugin.Media.Abstractions.MediaFile file, string fileName)
        {
            if (file == null)
            {
                return;
            }
            viewModel.IsLoading = true;
            StreamContent content = new StreamContent(file.GetStream());

            content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
            {
                Name     = "files",
                FileName = fileName
            };

            MultipartFormDataContent form = new MultipartFormDataContent();

            form.Add(content);

            var apiResponse = await BsdHttpClient.Instance().PostAsync(ApiRouter.USER_AVATAR_UPLOAD, form);

            if (apiResponse.IsSuccessStatusCode)
            {
                string      AvatarUrl = "avatar/" + fileName;
                ApiResponse response  = await ApiHelper.Post(ApiRouter.USER_AVATAR_UPDATE, AvatarUrl, true, false);

                if (response.IsSuccess)
                {
                    viewModel.User.AvatarUrl = AvatarUrl;

                    string AvatarFullUrl = viewModel.User.AvatarFullUrl;

                    image.Source = AvatarFullUrl;
                    UserLogged.SaveAvatar(AvatarFullUrl);

                    MessagingCenter.Send <ProfilePage, string>(this, "UpdateAvatar", AvatarUrl);
                    await DisplayAlert("", Language.cap_nhat_anh_dai_dien_thanh_cong, Language.dong);
                }
                else
                {
                    await DisplayAlert("", Language.khong_cap_nhat_duoc_anh_dai_dien, Language.dong);
                }
            }
            else
            {
                await DisplayAlert("", Language.khong_cap_nhat_duoc_anh_dai_dien, Language.dong);
            }
            viewModel.IsLoading = false;
        }
Esempio n. 10
0
 private byte[] ResizeImage(Plugin.Media.Abstractions.MediaFile imageFile)
 {
     if (imageFile != null)
     {
         using (MemoryStream ms = new MemoryStream())
         {
             imageFile.GetStream().CopyTo(ms);
             byte[] bytes = ms.ToArray();
             return(bytes);
         }
     }
     else
     {
         return(null);
     }
 }
Esempio n. 11
0
        private async void ChangeImage()
        {
            await CrossMedia.Current.Initialize();

            var source = await Application.Current.MainPage.DisplayActionSheet(
                Languages.ImageSource,
                Languages.Cancel,
                null,
                Languages.FromGallery,
                Languages.NewPicture);

            if (source == Languages.Cancel)
            {
                this.file = null;
                return;
            }

            if (source == Languages.NewPicture)
            {
                this.file = await CrossMedia.Current.TakePhotoAsync(
                    new StoreCameraMediaOptions
                {
                    Directory = "Sample",
                    Name      = "test.jpg",
                    PhotoSize = PhotoSize.Small,
                }
                    );
            }
            else
            {
                this.file = await CrossMedia.Current.PickPhotoAsync();
            }

            if (this.file != null)
            {
                this.ImageSource = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    return(stream);
                });
            }
        }
        private async void AddUserPhoto_Tapped(object sender, EventArgs e)
        {
            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await DisplayAlert("Alert", "not supprored", "ok");

                return;
            }
            var mediaoptions = new PickMediaOptions()
            {
                PhotoSize = PhotoSize.Medium
            };

            selectedimgfile = await CrossMedia.Current.PickPhotoAsync(mediaoptions);

            if (selectedimgfile == null)
            {
                await DisplayAlert("error", "tryagain", "ok");
            }
            image.Source = ImageSource.FromStream(() => selectedimgfile.GetStream());
        }
Esempio n. 13
0
		public async Task UploadPhoto(MediaFile file)
		{
			bool refreshAvatars = false;

			LoadingMessage = "Uploading Photo...";

			using (BusyContext ()) {
				using (App.Logger.TrackTimeContext ("UploadPhoto")) {
					try {
						if (!await RefreshToken ())
							return;

						var userManager = new UserManager (Settings.AccessToken);

						var stream = file.GetStream ();
						var newAvatar = await userManager.AddCustomAvatar (stream);
						if (newAvatar == null)
							return;

						Avatar = newAvatar.Location;
						Settings.Avatar = newAvatar.Location;
						Settings.CustomAvatar = newAvatar.Location;
						Settings.CustomAvatarId = newAvatar.Id;
						App.Logger.Track ("AvatarUploaded");
						OnPropertyChanged (AvatarUrlName);
						refreshAvatars = true;
					} catch (Exception ex) {
						App.Logger.Report (ex);
						RaiseError ("Avatar upload failed. Please try again.");
					}
				}
			}

			if (refreshAvatars)
				await ExecuteLoadAvatarsCommand ();
		}
        public async Task UploadVideoAsync(MediaFile file)
        {
            Processing = true;
            VideoServiceClient = new VideoServiceClient("9739e652e7214256ac48cb85e641a96e")
            {
                Timeout = TimeSpan.FromMinutes(10)
            };

            //Operation videoOperation;
            try
            {
                //Stream testStream = file.GetStream();

                using (Stream videoStream = file.GetStream())
                {
                    var operation =
                        await VideoServiceClient.CreateOperationAsync(videoStream, new FaceDetectionOperationSettings());

                    OperationResult result = await VideoServiceClient.GetOperationResultAsync(operation);
                    while (result.Status != OperationStatus.Succeeded && result.Status != OperationStatus.Failed)
                    {
                        Debug.WriteLine(
                            $"Server status: {result.Status}, wait {QueryWaitTime.TotalSeconds} seconds");
                        await Task.Delay(QueryWaitTime);
                        result = await VideoServiceClient.GetOperationResultAsync(operation);
                    }
                    Debug.WriteLine($"Finish processing with server status: {result.Status}");

                    // Processing finished, check result
                    if (result.Status == OperationStatus.Succeeded)
                    {
                        var faceTrackingResult = JsonConvert.DeserializeObject<FaceTracking>(result.ProcessingResult);
                        NaturalVideoHeight = faceTrackingResult.Height;
                        NaturalVideoWidth = faceTrackingResult.Width;
                        FrameHighlights = GetHighlights(result.ProcessingResult).ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                // ignored
            }

            Processing = false;
        }
Esempio n. 15
0
        public async Task VisionComputerVisionAsync(MediaFile file)
        {
            if (file == null)
            {
                WarningText = "Please take photo first";
            }
            else
            {
                Title = "Checking image";
                var computerVision = new ComputerVisionAPIV10();
                var analysisRects = await computerVision.AnalyzeImageWithHttpMessagesAsync(file.GetStream(), "Categories", null, "en", null,
                    Constants.CuomputerVisionApiKey);

                AnalysisCategories = string.Empty;
                DescriptionCaptions = string.Empty;
                AnalysisFaces = string.Empty;
                AnalysisTag = string.Empty;

                ////call from class library
                //var co = new CognitiveServiceClient();
                //var result = await co.ComputerVisionApiRequestAsync(Constants.CuomputerVisionApiKey, file.GetStream());
                ////var photoStream = await PclStorageStreamAsync(ImageUrl);
                //AnalysisResult analysisRects = await UploadAndAnalyzeImage(file.GetStream());
                var faceNo = 1;
                if (analysisRects != null)
                {
                    Title = "Here is the result";
                    foreach (var analysisRect in analysisRects.Categories)
                    {
                        AnalysisCategories += $" {analysisRect.Name} + Score: {analysisRect.Score}";
                    }

                    foreach (var descriptionCaption in analysisRects.Description.Captions)
                    {
                        DescriptionCaptions += $"{descriptionCaption.Text} + Confidence :{descriptionCaption.Confidence}";
                    }
                    if (analysisRects.Faces.Length >= 1)
                    {
                        Xywh = new string[analysisRects.Faces.Length];
                        for (int i = 0; i < analysisRects.Faces.Length; i++)
                        {

                            Xywh[i] =
                                $"{analysisRects.Faces[i].FaceRectangle.Left},{analysisRects.Faces[i].FaceRectangle.Top},{analysisRects.Faces[i].FaceRectangle.Width},{analysisRects.Faces[i].FaceRectangle.Height}";
                        }

                        //Xywh = new string[analysisRects.Faces.Length];
                        //foreach (var face in analysisRects.Faces)
                        //{
                        //    Xywh.Add($"{face.FaceRectangle.Left},{face.FaceRectangle.Top},{face.FaceRectangle.Width},{face.FaceRectangle.Height}");
                        //    //Xywh = $"{analysisRects.Faces[0].FaceRectangle.Left},{analysisRects.Faces[0].FaceRectangle.Top},{analysisRects.Faces[0].FaceRectangle.Width},{face.FaceRectangle.Height}";
                        //}
                        //Xywh = $"{analysisRects.Faces[0].FaceRectangle.Left},{analysisRects.Faces[0].FaceRectangle.Top},{analysisRects.Faces[0].FaceRectangle.Width},{analysisRects.Faces[0].FaceRectangle.Height}";
                    }
                    else
                    {
                        WarningText = "Can't detect face, please take another photo";
                        Xywh = new string[1];
                        Xywh[0] = ("0,0,0,0");

                    }

                    FaceMetadata = analysisRects.Faces;
                    foreach (var face in analysisRects.Faces)
                    {
                        AnalysisFaces += $"FaceNo: {faceNo} Age: {face.Age} + Gender: {face.Gender}";

                        //FaceMetadata = new List<string>
                        //{
                        //    $"{face.FaceRectangle.Width},{face.FaceRectangle.Height},{face.FaceRectangle.Left},{face.FaceRectangle.Top}"
                        //};
                        //Xywh = $"{face.FaceRectangle.Left},{face.FaceRectangle.Top},{face.FaceRectangle.Width},{face.FaceRectangle.Height}";

                        faceNo++;
                    }
                    foreach (var analysisRectsTag in analysisRects.Tags)
                    {
                        AnalysisTag += $"Confident: {analysisRectsTag.Confidence} + Name: {analysisRectsTag.Name}";
                    }

                    ImageMetadata = $"{analysisRects.Metadata.Width},{analysisRects.Metadata.Height}";

                    var value = $"Adult content: {analysisRects.Adult.IsAdultContent}, Image infor: {analysisRects.Metadata.Format} + Height: {analysisRects.Metadata.Height} + Width: {analysisRects.Metadata.Width}";
                    Title = value;
                }
            }

        }
Esempio n. 16
0
        public async Task VisionEmotionAsync(MediaFile file)
        {
            if (string.IsNullOrEmpty(ImageUrl))
            {
                WarningText = "Please take photo first";
            }
            else
            {
                Title = "Checking image";
                var emotion = new EmotionAPI();
                var result = await emotion.EmotionRecognitionWithHttpMessagesAsync(file.GetStream(), null, Constants.EmotionApiKey);

                var faceNo = 1;

                var value = "";
                //var test = await cognitiveServiceVision.VisionEmotionApiRequestAsync(Constants.EmotionApiKey, ImageUrl);
                //Emotion[] emotionRects = await cognitiveServiceVision.VisionEmotionApiRequestAsync(Constants.FaceApiKey,ImageUrl);
                //var photoStream = await PclStorageStreamAsync(ImageUrl);
                //Emotion[] emotionRects = await UploadAndDetectEmotion(await PclStorageStreamAsync(ImageUrl));

                if (result != null && result.Length > 0)
                {
                    Title = "Here is the result";
                    foreach (var emotionRect in result)
                    {
                        value +=
                            $"Face{faceNo} Anger: {emotionRect.Scores.Anger} Contempt: {emotionRect.Scores.Contempt} Disgust: {emotionRect.Scores.Disgust} Fear: {emotionRect.Scores.Fear} Happiness: {emotionRect.Scores.Happiness} Neutral: {emotionRect.Scores.Neutral} Sadness: {emotionRect.Scores.Sadness} Surprise: {emotionRect.Scores.Surprise}";
                        faceNo++;
                    }
                }
                else
                {
                    value = "No results";
                }
                CleanResult();
                Title = value;
            }
        }
Esempio n. 17
0
        public async Task VisionFaceCheckAsync(MediaFile file)
        {
            //var filePath = "Assets/carre_homme.jpg";
            //Image image = new Image();
            //image.Source = filePath;

            //ImageUrl = filePath;
            //var photoStream = await PclStorageStreamAsync(filePath);
            if (string.IsNullOrEmpty(ImageUrl))
            {
                WarningText = "Please take photo first";
            }
            else
            {
                var computerVision = new FaceAPIV10();
                var result = await computerVision.FaceDetectWithHttpMessagesAsync(file.GetStream(), null, null, null, null, Constants.FaceApiKey);
            }
        }
Esempio n. 18
0
        private async void Add_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(viewModel.GoiVayModel.Name))
            {
                await Shell.Current.DisplayAlert("", Language.vui_long_nhap_ten_goi_vay, Language.dong);

                return;
            }

            if (viewModel.MaxTimeOption == null)
            {
                await Shell.Current.DisplayAlert("", Language.vui_long_chon_thoi_han_vay_toi_da, Language.dong);

                return;
            }

            if (!EntryLaiSuat.Price.HasValue || EntryLaiSuat.Price.Value == 0)
            {
                await Shell.Current.DisplayAlert("", Language.vui_long_nhap_lai_suat, Language.dong);

                return;
            }

            if (!EntryMaxPrice.Price.HasValue || EntryMaxPrice.Price.Value == 0)
            {
                await Shell.Current.DisplayAlert("", Language.vui_long_chon_thoi_han_vay_toi_da, Language.dong);

                return;
            }

            if (string.IsNullOrWhiteSpace(viewModel.GoiVayModel.Condition))
            {
                await Shell.Current.DisplayAlert("", Language.vui_long_nhap_dieu_kien_vay, Language.dong);

                return;
            }

            // co chon hinh khac.
            if (imageFile != null)
            {
                string        fileName = Guid.NewGuid() + ".jpg";
                StreamContent content  = new StreamContent(imageFile.GetStream());
                content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    Name     = "file",
                    FileName = fileName
                };

                MultipartFormDataContent form = new MultipartFormDataContent();
                form.Add(content);
                var uploadImageResopnse = await UploadImage(form);

                if (uploadImageResopnse.IsSuccess)
                {
                    viewModel.GoiVayModel.Image = fileName;
                }
            }

            GoiVay goivay = new GoiVay();

            goivay.BankId      = viewModel.BankId;
            goivay.Name        = viewModel.GoiVayModel.Name;
            goivay.MaxTime     = viewModel.MaxTimeOption.Id;
            goivay.MaxTimeUnit = viewModel.MaxTimeUnitOption.Id;
            goivay.MaxPrice    = EntryMaxPrice.Price.Value;
            goivay.LaiSuat     = EntryLaiSuat.Price.Value;
            goivay.Condition   = viewModel.GoiVayModel.Condition;
            goivay.Description = viewModel.GoiVayModel.Description;
            goivay.Image       = viewModel.GoiVayModel.Image;


            ApiResponse response = null;

            loadingPopup.IsVisible = true;
            if (viewModel.GoiVayModel.Id == Guid.Empty)
            {
                response = await ApiHelper.Post(ApiRouter.BANK_GOIVAY, goivay, true);
            }
            else
            {
                goivay.Id = viewModel.GoiVayModel.Id;
                response  = await ApiHelper.Put(ApiRouter.BANK_GOIVAY, goivay, true);
            }

            if (response.IsSuccess)
            {
                this.OnSaved?.Invoke(this, EventArgs.Empty);
                loadingPopup.IsVisible = false;
                MessagingCenter.Send <AddLoanView>(this, "OnSave");
                ToastMessageHelper.ShortMessage(Language.luu_thanh_cong);
            }
            else
            {
                await Shell.Current.DisplayAlert("", response.Message, Language.dong);

                loadingPopup.IsVisible = false;
            }
            loadingPopup.IsVisible = false;
        }
        private async void SignUp_Btn_Clicked(object sender, EventArgs e)
        {
            bool ValidEmail = false;

            if (string.IsNullOrEmpty(UserEmail.Text))
            {
                ValidEmail = false;
            }

            else
            if (UserEmail.Text.Contains("@") && UserEmail.Text.Contains(".com"))
            {
                ValidEmail = true;
            }

            if (string.IsNullOrEmpty(UserName.Text) || string.IsNullOrEmpty(UserEmail.Text) || string.IsNullOrEmpty(UserPhone.Text) || string.IsNullOrEmpty(UserPassword.Text) || ValidEmail == false)
            {
                if (string.IsNullOrEmpty(UserName.Text))
                {
                    NameFrame.BorderColor = Color.Red;
                }
                else
                {
                    NameFrame.BorderColor = Color.LightGreen;
                }

                if (string.IsNullOrEmpty(UserEmail.Text) || ValidEmail == false)
                {
                    EmailFrame.BorderColor = Color.Red;
                }
                else
                {
                    EmailFrame.BorderColor = Color.LightGreen;
                }

                if (string.IsNullOrEmpty(UserPhone.Text))
                {
                    PhoneFrame.BorderColor = Color.Red;
                }
                else
                {
                    PhoneFrame.BorderColor = Color.LightGreen;
                }

                if (string.IsNullOrEmpty(UserPassword.Text))
                {
                    PasswordFrame.BorderColor = Color.Red;
                }
                else
                {
                    PasswordFrame.BorderColor = Color.LightGreen;
                }
            }

            else
            {
                User user = new User();
                user.Name        = UserName.Text;
                user.Email       = UserEmail.Text;
                user.Password    = UserPassword.Text;
                user.PhoneNumber = UserPhone.Text;
                var x = image.Source.ToString();
                if (x == "File: userprofile.jpg")
                {
                    user.Image = "/uploads/64884803.png";
                }
                else
                {
                    Stream stream    = selectedimgfile.GetStream();
                    var    imagePath = await RegisterViewModel.UploadImage(stream, selectedimgfile.Path);

                    user.Image = imagePath;
                }

                var userData = await RegisterViewModel.Register(user);

                Application.Current.Properties["UserID"]     = userData.ID.ToString();
                Application.Current.Properties["IsLoggedin"] = "True";

                await Navigation.PushAsync(new HomePage());
            }
        }