示例#1
0
        protected void SetViewBag(bool isCreate)
        {
            //Mặt bằng
            //var matBang = _repository.GetRepository<MatBang>().GetAll();
            //ViewBag.MatBang = matBang.ToList().ToSelectList();

            //Địa chỉ quận - đường
            NhaCreatingViewModel model = new NhaCreatingViewModel();

            var quan = _repository.GetRepository <Quan>().GetAll().OrderBy(o => o.Name).ToList();

            if (isCreate)
            {
                ViewBag.QuanDropdownlist  = new SelectList(quan, "Id", "Name", model.QuanId);
                ViewBag.DuongDropdownlist = new SelectList(_repository.GetRepository <Duong>().GetAll(o => o.QuanId == model.QuanId).OrderBy(o => o.Name).ToList(), "Id", "Name", model.DuongId);
            }
            else
            {
                var quanUpdate = _repository.GetRepository <Quan>().GetAll();
                ViewBag.QuanDropdownlist = quanUpdate.ToList().ToSelectList();

                var duong = _repository.GetRepository <Duong>().GetAll();
                ViewBag.DuongDropdownlist = duong.ToList().ToSelectList();
            }

            //var quan = _repository.GetRepository<Quan>().GetAll().OrderBy(o => o.Name).ToList();
            //ViewBag.QuanDropdownlist = new SelectList(quan, "Id", "Name", model.QuanId);
            //ViewBag.DuongDropdownlist = new SelectList(_repository.GetRepository<Duong>().GetAll(o => o.QuanId == model.QuanId).OrderBy(o => o.Name).ToList(), "Id", "Name", model.DuongId);

            var listYesOrNo = new SelectList(new[]
            {
                new { ID = "0", Name = "Không" },
                new { ID = "1", Name = "Có" },
            }, "ID", "Name", 1);

            ViewBag.ListYesOrNo = listYesOrNo;

            //Nội thất khách thuê cũ
            var noiThatKhachThueCu = _repository.GetRepository <NoiThatKhachThueCu>().GetAll();

            ViewBag.NoiThatKhachThueCu = noiThatKhachThueCu.ToList().ToSelectList();

            //Đánh giá phù hợp với
            //var danhGiaPhuHopVoi = _repository.GetRepository<DanhGiaPhuHopVoi>().GetAll();
            //ViewBag.DanhGiaPhuHopVoi = danhGiaPhuHopVoi.ToList().ToSelectList();

            //Cấp độ theo dõi
            var capDoTheoDoi = _repository.GetRepository <CapDoTheoDoi>().GetAll();

            ViewBag.CapDoTheoDoi = capDoTheoDoi.ToList().ToSelectList();
        }
示例#2
0
        public async Task <ActionResult> Create()
        {
            SetViewBag(true);

            //Mặt bằng
            var matBang        = _repository.GetRepository <MatBang>().GetAll();
            var model          = new NhaCreatingViewModel();
            var listMatBangArr = new List <MatBangItem>();

            if (matBang.Any())
            {
                foreach (var item in matBang)
                {
                    listMatBangArr.Add(new MatBangItem {
                        FieldKey = item.Id, FieldName = item.Name, IsSelected = false
                    });
                }
            }

            model.ListMatBangArr = listMatBangArr;

            //Đánh giá phù hợp với
            var danhGia        = _repository.GetRepository <DanhGiaPhuHopVoi>().GetAll();
            var listDanhGiaArr = new List <DanhGiaPhuHopVoiItem>();

            if (danhGia.Any())
            {
                foreach (var item in danhGia)
                {
                    listDanhGiaArr.Add(new DanhGiaPhuHopVoiItem {
                        FieldKey = item.Id, FieldName = item.Name, IsSelected = false
                    });
                }
            }

            model.ListDanhGiaPhuHopVoiArr = listDanhGiaArr;

            return(View(model));
        }
示例#3
0
        public async Task <ActionResult> Create(NhaCreatingViewModel model)
        {
            if (ModelState.IsValid)
            {
                Nha nha = new Nha();

                decimal giaThueBQ = 0;

                if (!string.IsNullOrEmpty(model.TongGiaThue) && !string.IsNullOrEmpty(model.TongDienTichSuDung))
                {
                    giaThueBQ = Convert.ToDecimal(model.TongGiaThue) / Convert.ToDecimal(model.TongDienTichSuDung);
                }


                nha.MatBangId              = model.MatBangId;
                nha.QuanId                 = Convert.ToInt64(model.QuanId);
                nha.DuongId                = Convert.ToInt64(model.DuongId);
                nha.SoNha                  = StringHelper.KillChars(model.SoNha);
                nha.TenToaNha              = StringHelper.KillChars(model.TenToaNha);
                nha.MatTienTreoBien        = string.IsNullOrEmpty(model.MatTienTreoBien) ? 0 : float.Parse(model.MatTienTreoBien, CultureInfo.InvariantCulture.NumberFormat);
                nha.BeNgangLotLong         = string.IsNullOrEmpty(model.BeNgangLotLong) ? 0 : float.Parse(model.BeNgangLotLong, CultureInfo.InvariantCulture.NumberFormat);
                nha.DienTichDat            = string.IsNullOrEmpty(model.DienTichDat) ? 0 : float.Parse(model.DienTichDat, CultureInfo.InvariantCulture.NumberFormat);
                nha.DienTichDatSuDungTang1 = string.IsNullOrEmpty(model.DienTichDatSuDungTang1) ? 0 : float.Parse(model.DienTichDatSuDungTang1, CultureInfo.InvariantCulture.NumberFormat);
                nha.SoTang                 = string.IsNullOrEmpty(model.SoTang) ? 0 : Convert.ToInt32(model.SoTang);
                nha.TongDienTichSuDung     = string.IsNullOrEmpty(model.TongDienTichSuDung) ? 0 : float.Parse(model.TongDienTichSuDung, CultureInfo.InvariantCulture.NumberFormat);
                nha.DiChungChu             = model.DiChungChu == "1" ? true : false;
                nha.Ham                  = model.Ham == "1" ? true : false;
                nha.ThangMay             = model.ThangMay == "1" ? true : false;
                nha.NoiThatKhachThueCuId = Convert.ToInt32(model.NoiThatKhachThueCuId);
                nha.DanhGiaPhuHopVoiId   = model.DanhGiaPhuHopVoiId;
                nha.TongGiaThue          = string.IsNullOrEmpty(model.TongGiaThue) ? 0 : Convert.ToDecimal(model.TongGiaThue);
                nha.GiaThueBQ            = giaThueBQ; //string.IsNullOrEmpty(model.GiaThueBQ) ? 0 : Convert.ToDecimal(model.GiaThueBQ);
                nha.TenNguoiLienHeVaiTro = StringHelper.KillChars(model.TenNguoiLienHeVaiTro);
                nha.SoDienThoai          = StringHelper.KillChars(model.SoDienThoai);
                nha.NgayCNHenLienHeLai   = string.IsNullOrEmpty(model.NgayCNHenLienHeLai) ? (DateTime?)null : DateTime.ParseExact(model.NgayCNHenLienHeLai, "dd/MM/yyyy", CultureInfo.InvariantCulture);

                nha.CapDoTheoDoiId = Convert.ToInt32(model.CapDoTheoDoiId);

                nha.ImageDescription1 = StringHelper.KillChars(model.ImageDescription1);
                nha.ImageDescription2 = StringHelper.KillChars(model.ImageDescription2);
                nha.ImageDescription3 = StringHelper.KillChars(model.ImageDescription3);
                nha.ImageDescription4 = StringHelper.KillChars(model.ImageDescription4);
                nha.GhiChu            = StringHelper.KillChars(model.GhiChu);
                nha.NgayTao           = DateTime.Now;
                nha.NguoiTaoId        = AccountId;
                nha.NguoiPhuTrachId   = AccountId;
                nha.TrangThai         = 0; //Chờ duyệt

                int result = 0;
                try
                {
                    result = await _repository.GetRepository <Nha>().CreateAsync(nha, AccountId);
                }
                catch { }
                if (result > 0)
                {
                    TempData["Success"] = "Nhập dữ liệu nhà mới thành công!";
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.DangMatBang = await _repository.GetRepository <MatBang>().GetAllAsync();

                ModelState.AddModelError(string.Empty, "Nhập dữ liệu nhà mới không thành công! Vui lòng kiểm tra và thử lại!");
                return(View(model));
            }
        }