Пример #1
0
        ////cap nhat nhat ky
        public async void UpdateDiary_Tapped(object sender2, EventArgs e2)
        {
            ProjectDiary item       = ((sender2 as Telerik.XamarinForms.Primitives.RadBorder).GestureRecognizers[0] as TapGestureRecognizer).CommandParameter as ProjectDiary;
            var          apireponse = await ApiHelper.Get <ProjectDiary>($"{ApiRouter.PROJECT_DIARY_GET_ONE_PROJECTDIARY}/{item.Id}");

            if (!apireponse.IsSuccess)
            {
                return;
            }
            var model = apireponse.Content as ProjectDiary;
            var view  = new ModalDiaryContentView(model.Id, model.ProjectId);

            ModalAddGhiNhan.Body = view;
            await ModalAddGhiNhan.Show();

            view.OnSaved += async(sender, e) =>
            {
                await viewModel.GetProjectDiary(_id);

                await ModalAddGhiNhan.Hide();

                ToastMessageHelper.ShortMessage(Language.cap_nhat_thong_tin_thanh_cong);
            };
            view.OnCancel += async(sender, e) =>
            {
                await ModalAddGhiNhan.Hide();
            };
        }
Пример #2
0
        ////project diary
        public async void AddDiary_Tapped(object sender1, EventArgs e1)// tapped them ghi nhan
        {
            var view = new ModalDiaryContentView(null, _id);

            ModalAddGhiNhan.Body = view;
            await ModalAddGhiNhan.Show();

            view.OnSaved += async(sender, e) =>
            {
                await viewModel.GetProjectDiary(_id);

                await ModalAddGhiNhan.Hide();

                ToastMessageHelper.ShortMessage(Language.them_nhat_ky_thanh_cong);
            };
            view.OnCancel += async(sender, e) =>
            {
                await ModalAddGhiNhan.Hide();
            };
        }
Пример #3
0
        public async void Save_Clicked(object sender1, EventArgs e1)
        {
            if (SwitchIsNegotiate.IsToggled)
            {
                SwitchIsPriceRange.IsToggled = false;
            }

            //kiem tra null Tieu de
            if (viewModel.AddProjectModel.Name == null)
            {
                await DisplayAlert(Language.thong_bao, Language.vui_long_nhap_tieu_de_du_an, Language.dong);

                return;
            }

            //kiem tra null Loai bat dong san
            if (viewModel.LoaiDuAnSelecteIds == null)
            {
                await DisplayAlert(Language.thong_bao, Language.vui_long_chon_loai_bat_dong_san, Language.dong);

                return;
            }

            //kiem tra null Trang thai
            if (viewModel.AddProjectModel.TrangThai == null)
            {
                await DisplayAlert(Language.thong_bao, Language.vui_long_chon_trang_thai, Language.dong);

                return;
            }

            // kiem tra Null khoang gia
            if (SwitchIsPriceRange.IsToggled == true)
            {
                if (viewModel.AddProjectModel.PriceFrom == null || viewModel.AddProjectModel.PriceTo == null)
                {
                    await DisplayAlert(Language.thong_bao, Language.vui_long_nhap_khoang_gia, Language.dong);

                    return;
                }
            }
            if (SwitchIsNegotiate.IsToggled == false && SwitchIsPriceRange.IsToggled == false)
            {
                if (viewModel.AddProjectModel.PriceFrom == null)
                {
                    await DisplayAlert(Language.thong_bao, Language.vui_long_nhap_gia, Language.dong);

                    return;
                }
            }


            //kiem tra null dien tich san trung binh
            if (SwitchDienTichSanTrungBinh.IsToggled == true)
            {
                if (string.IsNullOrWhiteSpace(DecimailEntDienTichSanTrungBinh_From.Text) || string.IsNullOrWhiteSpace(DecimalEntDienTichSanTrungBinh_To.Text))
                {
                    await DisplayAlert(Language.thong_bao, Language.vui_long_nhap_day_du_thong_tin_dien_tich_san, Language.dong);

                    return;
                }
            }

            //kiem tra Null dien tich cay xanh
            if (SwitchDienTichCayXanh.IsToggled == true)
            {
                if (string.IsNullOrWhiteSpace(DecimalDienTichCayXanhFrom.Text) || string.IsNullOrWhiteSpace(DecimalDienTichCayXanhTo.Text))
                {
                    await DisplayAlert(Language.thong_bao, Language.vui_long_nhap_day_du_thong_tin_dien_tich_cay_xanh, Language.dong);

                    return;
                }
            }

            // kiem ta Null dien tich khu dat
            if (SwitchDienTichKhuDat.IsToggled == true)
            {
                if (string.IsNullOrWhiteSpace(DecimalDienTichKhuDatFrom.Text) || string.IsNullOrWhiteSpace(DecimalDienTichKhuDatTo.Text))
                {
                    await DisplayAlert(Language.thong_bao, Language.vui_long_nhap_day_du_thong_tin_dien_tich_khu_dat, Language.dong);

                    return;
                }
            }

            //kiem tra null dien tich xay dung
            if (SwitchDienTichXayDung.IsToggled == true)
            {
                if (string.IsNullOrWhiteSpace(DecimalDienTichXayDungFrom.Text) || string.IsNullOrWhiteSpace(DecimalDienTichXayDungTo.Text))
                {
                    await DisplayAlert(Language.thong_bao, Language.vui_long_nhap_day_du_thong_tin_dien_tich_xay_dung, Language.dong);

                    return;
                }
            }

            if (DecimalEntryMatDoXayDung.Price > 100)
            {
                await DisplayAlert(Language.thong_bao, Language.mat_do_xay_dung_khong_dung_vui_long_nhap_lai, Language.dong);

                return;
            }
            //set loai bat dong san
            if (viewModel.LoaiDuAnSelecteIds != null && viewModel.LoaiDuAnSelecteIds.Any())
            {
                viewModel.AddProjectModel.CategoriBDS = string.Join(",", viewModel.LoaiDuAnSelecteIds.ToArray());
            }
            else
            {
                viewModel.AddProjectModel.CategoriBDS = null;
            }

            //set trang thai
            if (viewModel.AddProjectModel.TrangThai != null)
            {
                viewModel.AddProjectModel.Status = viewModel.AddProjectModel.TrangThai.Id.ToString();
            }
            else
            {
                viewModel.AddProjectModel.Status = null;
            }

            //set dia chi va kiem tra null
            if (viewModel.AddProjectModel.Province != null)
            {
                viewModel.AddProjectModel.ProvinceId = viewModel.AddProjectModel.Province.Id;
            }
            else
            {
                await DisplayAlert(Language.thong_bao, Language.vui_long_chon_tinh_thanh, Language.dong);

                return;
            }
            if (viewModel.AddProjectModel.District != null)
            {
                viewModel.AddProjectModel.DistrictId = viewModel.AddProjectModel.District.Id;
            }
            else
            {
                await DisplayAlert(Language.thong_bao, Language.vui_long_chon_quan_huyen, Language.dong);

                return;
            }
            if (viewModel.AddProjectModel.Ward != null)
            {
                viewModel.AddProjectModel.WardId = viewModel.AddProjectModel.Ward.Id;
            }
            else
            {
                await DisplayAlert(Language.thong_bao, Language.vui_long_chon_phuong_xa, Language.dong);

                return;
            }

            if (viewModel.AddProjectModel.Description == null)
            {
                await DisplayAlert(Language.thong_bao, Language.vui_long_nhap_mo_ta, Language.dong);

                return;
            }

            if (viewModel.Media.Count == 0)
            {
                await DisplayAlert(Language.thong_bao, Language.vui_long_chon_hinh, Language.dong);

                return;
            }
            if (viewModel.Media.Count < 3)
            {
                await DisplayAlert(Language.thong_bao, Language.chon_it_nhat_3_hinh, Language.dong);

                return;
            }

            try
            {
                // lay dia chi
                IEnumerable <Position> result = await new Geocoder().GetPositionsForAddressAsync(viewModel.AddProjectModel.Address);
                if (result.Any())
                {
                    viewModel.AddProjectModel.Lat  = result.First().Latitude;
                    viewModel.AddProjectModel.Long = result.First().Longitude;
                }
                else
                {
                    await DisplayAlert("", Language.dia_chi_khong_thay_tren_ban_do_vui_long_nhap_lai, Language.dong);
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("", Language.dia_chi_khong_thay_tren_ban_do_vui_long_nhap_lai, Language.dong);

                return;
            }

            viewModel.AddProjectModel.MatDoXayDungPercent       = DecimalEntryMatDoXayDung.Price;
            viewModel.AddProjectModel.DienTichSanTrungBinh_From = DecimailEntDienTichSanTrungBinh_From.Price;
            viewModel.AddProjectModel.DienTichSanTrungBinh_To   = DecimalEntDienTichSanTrungBinh_To.Price;
            viewModel.AddProjectModel.DienTichXayDung_From      = DecimalDienTichXayDungFrom.Price;
            viewModel.AddProjectModel.DienTichXayDung_To        = DecimalDienTichXayDungTo.Price;
            viewModel.AddProjectModel.DienTichKhuDat_From       = DecimalDienTichKhuDatFrom.Price;
            viewModel.AddProjectModel.DienTichKhuDat_To         = DecimalDienTichKhuDatTo.Price;
            viewModel.AddProjectModel.DienTichCayXanh_From      = DecimalDienTichCayXanhFrom.Price;
            viewModel.AddProjectModel.DienTichCayXanh_To        = DecimalDienTichCayXanhTo.Price;

            loadingPopup.IsVisible = true;


            if (viewModel.TienIchDuAnSelecteIds != null && viewModel.TienIchDuAnSelecteIds.Any())
            {
                viewModel.AddProjectModel.ImageUtilities = string.Join(",", viewModel.TienIchDuAnSelecteIds.ToArray());
            }
            else
            {
                viewModel.AddProjectModel.ImageUtilities = null;
            }


            // set image va avatar
            MultipartFormDataContent form = new MultipartFormDataContent();

            string[] imageList = new string[viewModel.Media.Count];
            for (int i = 0; i < viewModel.Media.Count; i++)
            {
                var item = viewModel.Media[i];
                // chua upload. upload roi link = null
                if (string.IsNullOrEmpty(item.Path) == false) // co link la co chon tu dien thoai.
                {
                    imageList[i] = $"{Guid.NewGuid().ToString()}.jpg";
                    var stream  = new MemoryStream(File.ReadAllBytes(item.Path));
                    var content = new StreamContent(stream);
                    content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                    {
                        Name     = "files" + i,
                        FileName = imageList[i]
                    };
                    form.Add(content);
                }
                else
                {
                    imageList[i] = item.PreviewPath.Replace(Configuration.ApiConfig.CloudStorageApiCDN + "/project/", "");
                }
            }
            if (imageList.Length > 8)
            {
                await DisplayAlert("", Language.vui_long_upload_toi_da_8_hinh_anh_bat_dong_san, Language.dong);

                loadingPopup.IsVisible = false;
                return;
            }

            viewModel.AddProjectModel.Avatar = imageList[0];
            viewModel.AddProjectModel.Images = string.Join(",", imageList);

            bool ImageUploaded = true;

            if (viewModel.Media.Any(x => x.Path != null))
            {
                ApiResponse uploadImageResponse = await UploadImage(form);

                if (!uploadImageResponse.IsSuccess)
                {
                    await DisplayAlert("", Language.hinh_anh_vuot_qua_dung_luong_vui_long_thu_lai, Language.dong);

                    ImageUploaded          = false;
                    loadingPopup.IsVisible = false;
                }
            }
            else
            {
                ImageUploaded = true; // ko can upload
            }
            if (ImageUploaded)        // neu khong can upload hoac up load thanh cong thi moi goi api.
            {
                ApiResponse apiResponse = null;
                if (this._id == Guid.Empty)
                {
                    viewModel.AddProjectModel.Id = Guid.NewGuid();
                    apiResponse = await ApiHelper.Post("api/project", viewModel.AddProjectModel, true);

                    if (apiResponse.IsSuccess)
                    {
                        MessagingCenter.Send <AddProjectPage>(this, "OnSaveProject");
                        var answer = await DisplayAlert(Language.thong_bao, Language.ban_co_muon_bo_sung_nhat_ky_du_an_khong, Language.dong_y, Language.huy);

                        if (answer)
                        {
                            _id = viewModel.AddProjectModel.Id;
                            stThongTinBoSung.IsVisible = true;
                            var view = new ModalDiaryContentView(null, _id);
                            ModalAddGhiNhan.Body = view;
                            await ModalAddGhiNhan.Show();

                            view.OnSaved += async(sender, e) =>
                            {
                                await viewModel.GetProjectDiary(_id);

                                await ModalAddGhiNhan.Hide();

                                ToastMessageHelper.ShortMessage(Language.them_ghi_nhan_thanh_cong);
                            };
                            view.OnCancel += async(sender, e) =>
                            {
                                await ModalAddGhiNhan.Hide();
                            };
                        }
                        else
                        {
                            await Shell.Current.Navigation.PopAsync();

                            ToastMessageHelper.ShortMessage(Language.luu_thanh_cong);
                        }
                    }
                }
                else
                {
                    apiResponse = await ApiHelper.Post("api/project/update", viewModel.AddProjectModel, true);

                    if (apiResponse.IsSuccess)
                    {
                        await Shell.Current.Navigation.PopAsync();

                        MessagingCenter.Send <AddProjectPage>(this, "OnSaveProject");
                        ToastMessageHelper.ShortMessage(Language.cap_nhat_thong_tin_thanh_cong);
                    }
                }
                if (!apiResponse.IsSuccess)
                {
                    loadingPopup.IsVisible = false;
                    await DisplayAlert("", Language.khong_the_luu_du_an_vui_long_thu_lai, Language.dong);
                }
            }
            loadingPopup.IsVisible = false;
        }