Пример #1
0
        public ActionResult Save(RealEstateCreateViewModel model)
        {
            if (RealEstateQueries.CheckExistRealEstate(UserQueries.GetCurrentUsername(), model.Name))
            {
                ModelState.AddModelError("CheckExistRealEstate", "Bất động sản này đã tồn tại, vui lòng nhập tên khác");
            }

            if (ModelState.IsValid)
            {
                model.Liabilities = (RealEstateLiabilityListCreateViewModel)HttpContext.Session["LIABILITIES"];
                string user   = UserQueries.GetCurrentUsername();
                int    result = RealEstateQueries.CreateRealEstate(model, user);
                if (result > 0)
                {
                    return(Content("success"));
                }
                else
                {
                    return(Content("failed"));
                }
            }
            else
            {
                model.IsInDebt = false;
                return(PartialView("_RealEstateForm", model));
            }
        }
Пример #2
0
        public ActionResult _RealEstateUpdateForm(RealEstateUpdateViewModel model)
        {
            double totalLiabilityValue = GetLiabilityValueOfRealEstate(model.Id);

            if (model.Value < totalLiabilityValue && totalLiabilityValue > 0)
            {
                ModelState.AddModelError("CompareRealEstateValueAndLiabilityValue", "Giá trị tổng số nợ không vượt quá giá trị bất động sản");
            }
            var realEstate = RealEstateQueries.GetRealEstateById(model.Id);

            if (!realEstate.Name.Equals(model.Name) && RealEstateQueries.CheckExistRealEstate(UserQueries.GetCurrentUsername(), model.Name))
            {
                ModelState.AddModelError("CheckExistRealEstate", "Bất động sản này đã tồn tại, vui lòng nhập tên khác");
            }

            if (ModelState.IsValid)
            {
                int result = RealEstateQueries.UpdateRealEstate(model);
                if (result > 0)
                {
                    return(Content("success"));
                }
                else
                {
                    return(Content("failed"));
                }
            }
            else
            {
                return(PartialView(model));
            }
        }
Пример #3
0
        public ActionResult _Create(RealEstateCreateViewModel model)
        {
            RealEstateLiabilityListCreateViewModel liabilities = (RealEstateLiabilityListCreateViewModel)HttpContext.Session["LIABILITIES"];
            double totalLiabilityValue = 0;

            if (liabilities != null)
            {
                totalLiabilityValue = liabilities.Liabilities.Sum(x => x.Value.HasValue ? x.Value.Value : 0);
            }

            if (model.Value < totalLiabilityValue && totalLiabilityValue > 0)
            {
                ModelState.AddModelError("CompareRealEstateValueAndLiabilityValue", "Giá trị tổng số nợ không vượt quá giá trị bất động sản");
            }

            if (RealEstateQueries.CheckExistRealEstate(UserQueries.GetCurrentUsername(), model.Name))
            {
                ModelState.AddModelError("CheckExistRealEstate", "Bất động sản này đã tồn tại, vui lòng nhập tên khác");
            }

            if (ModelState.IsValid)
            {
                HttpContext.Session["REAL_ESTATE"] = model;
                return(Content("success"));
            }
            else
            {
                return(PartialView("_RealEstateForm", model));
            }
        }