public async Task SetForm()
        {
            var response = await ApiHelper.Get <GoiVay>(ApiRouter.BANK_GOIVAY + "/" + _id);

            if (response.IsSuccess && response.Content != null)
            {
                this._goiVay = response.Content as GoiVay;
                this.Title   = _goiVay.Name;

                image.Success += (sender1, e1) =>
                {
                    heightImage = e1.ImageInformation.OriginalHeight;
                    widthImage  = e1.ImageInformation.OriginalWidth;
                    setSizeImage();
                };
                image.Source = ImageSource.FromUri(new Uri(_goiVay.ImageFullUrl));

                lblNganHang.Text    = _goiVay.Bank.Name;
                lblGoiVayName.Text  = _goiVay.Name;
                lblMaxPrice.Text    = DecimalHelper.DecimalToText(_goiVay.MaxPrice) + "%";
                lblMaxTime.Text     = _goiVay.MaxTime + " " + (_goiVay.MaxTimeUnit == 0 ? Language.year.ToLower() : Language.month.ToLower());
                lblLaiSuat.Text     = DecimalHelper.DecimalToText(_goiVay.LaiSuat) + "%";
                lblCondition.Text   = _goiVay.Condition;
                lblDescription.Text = _goiVay.Description;

                lblEmpName.Text = _goiVay.User.FullName;
                lblPhone.Text   = _goiVay.User.Phone;

                imageAvatar.Source = _goiVay.User.AvatarFullUrl;

                lblAddress.Text = _goiVay.Employee.Address;
            }
        }
Beispiel #2
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;
        }