Esempio n. 1
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));
            }
        }
Esempio n. 2
0
        public static RealEstateUpdateViewModel GetRealEstateById(int id)
        {
            RealEstateUpdateViewModel viewmodel = new RealEstateUpdateViewModel();
            Entities entities   = new Entities();
            var      realEstate = entities.Assets.Where(x => x.Id == id).FirstOrDefault();

            viewmodel.Id    = realEstate.Id;
            viewmodel.Name  = realEstate.AssetName;
            viewmodel.Value = realEstate.Value;
            if (realEstate.Incomes1.Where(x => !x.DisabledDate.HasValue).Any())
            {
                viewmodel.Income = realEstate.Incomes1.FirstOrDefault().Value;
            }
            else
            {
                viewmodel.Income = 0;
            }
            return(viewmodel);
        }
Esempio n. 3
0
        public static int UpdateRealEstate(RealEstateUpdateViewModel model)
        {
            Entities entities = new Entities();
            DateTime current  = DateTime.Now;

            var realEstate = entities.Assets.Where(x => x.Id == model.Id).FirstOrDefault();

            realEstate.AssetName = model.Name;
            realEstate.Value     = model.Value.Value;
            entities.Assets.Attach(realEstate);
            entities.Entry(realEstate).State = System.Data.Entity.EntityState.Modified;

            if (entities.Incomes.Where(x => x.AssetId == model.Id).Any())
            {
                var income = entities.Incomes.Where(x => x.AssetId == model.Id).FirstOrDefault();
                income.Value = model.Income.HasValue ? model.Income.Value : 0;
                income.Name  = "Thu nhập cho thuê từ " + model.Name;
                entities.Incomes.Attach(income);
                entities.Entry(income).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                Incomes income = new Incomes();
                income.Name        = "Thu nhập cho thuê từ " + realEstate.AssetName;
                income.Value       = model.Income.Value;
                income.IncomeDay   = 1;
                income.StartDate   = current;
                income.CreatedDate = current;
                income.CreatedBy   = Constants.Constants.USER;
                income.IncomeType  = (int)Constants.Constants.INCOME_TYPE.REAL_ESTATE_INCOME;
                income.Username    = realEstate.Username;
                realEstate.Incomes1.Add(income);
            }

            return(entities.SaveChanges());
        }
Esempio n. 4
0
        public ActionResult _RealEstateUpdateForm(int id)
        {
            RealEstateUpdateViewModel model = RealEstateQueries.GetRealEstateById(id);

            return(PartialView(model));
        }