public ActionResult _LiabilityUpdateForm(RealEstateLiabilityCreateViewModel model) { if (ModelState.IsValid) { RealEstateLiabilityListCreateViewModel liabilities = (RealEstateLiabilityListCreateViewModel)HttpContext.Session["LIABILITIES"]; RealEstateLiabilityCreateViewModel updateModel = liabilities.Liabilities.Where(x => x.Id == model.Id).FirstOrDefault(); updateModel.Value = model.Value; RealEstateCreateViewModel realEstate = (RealEstateCreateViewModel)HttpContext.Session["REAL_ESTATE"]; double totalLiabilityValue = liabilities != null?liabilities.Liabilities.Sum(x => x.Value.HasValue?x.Value.Value : 0) : 0; if (realEstate.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"); return(PartialView(model)); } else { updateModel.Id = model.Id; updateModel.Source = model.Source; updateModel.InterestType = model.InterestType; updateModel.InterestRate = model.InterestRate; updateModel.StartDate = model.StartDate; updateModel.EndDate = model.EndDate; HttpContext.Session["LIABILITIES"] = liabilities; return(Content("success")); } } else { return(PartialView(model)); } }
public static int AddRealEstateLiability(RealEstateLiabilityCreateViewModel model) { DateTime current = DateTime.Now; Entities entities = new Entities(); string username = entities.Assets.Where(x => x.Id == model.AssetId).FirstOrDefault().Username; Liabilities liability = new Liabilities(); liability.Name = model.Source; liability.Value = model.Value.Value; liability.InterestType = model.InterestType; liability.InterestRate = model.InterestRate.Value; liability.InterestRatePerX = model.InterestRatePerX; liability.StartDate = model.StartDate.Value; liability.EndDate = model.EndDate.Value; liability.LiabilityType = (int)Constants.Constants.LIABILITY_TYPE.REAL_ESTATE; liability.CreatedDate = current; liability.CreatedBy = Constants.Constants.USER; liability.Username = username; liability.AssetId = model.AssetId; entities.Liabilities.Add(liability); return(entities.SaveChanges()); }
public ActionResult _LiabilityUpdateForm(int id) { RealEstateLiabilityListCreateViewModel liabilities = (RealEstateLiabilityListCreateViewModel)HttpContext.Session["LIABILITIES"]; RealEstateLiabilityCreateViewModel model = liabilities.Liabilities.Where(x => x.Id == id).FirstOrDefault(); return(PartialView(model)); }
public ActionResult _LiabilityForm2nd(RealEstateLiabilityCreateViewModel model) { double totalLiabilityValue = GetLiabilityValueOfRealEstate(model.AssetId); double realEstateValue = RealEstateQueries.GetRealEstateValue(model.AssetId); if (realEstateValue < totalLiabilityValue + model.Value && totalLiabilityValue + model.Value > 0) { ModelState.AddModelError("CompareRealEstateValueAndLiabilityValue", "Giá trị tổng số nợ không vượt quá giá trị bất động sản"); } if (ModelState.IsValid) { int result = RealEstateLiabilityQueries.AddRealEstateLiability(model); if (result > 0) { return(Content("success")); } else { return(Content("failed")); } } else { return(PartialView(model)); } }
public ActionResult _LiabilityForm2nd(int id) { RealEstateLiabilityCreateViewModel model = new RealEstateLiabilityCreateViewModel(); model.AssetId = id; return(PartialView(model)); }
public ActionResult _LiabilityForm(RealEstateLiabilityCreateViewModel model) { if (ModelState.IsValid) { int id = 1; RealEstateLiabilityListCreateViewModel liabilities = (RealEstateLiabilityListCreateViewModel)HttpContext.Session["LIABILITIES"]; RealEstateCreateViewModel realEstate = (RealEstateCreateViewModel)HttpContext.Session["REAL_ESTATE"]; double totalLiabilityValue = liabilities != null?liabilities.Liabilities.Sum(x => x.Value.HasValue?x.Value.Value : 0) : 0; if (realEstate.Value < totalLiabilityValue + model.Value && totalLiabilityValue + model.Value > 0) { ModelState.AddModelError("CompareRealEstateValueAndLiabilityValue", "Giá trị tổng số nợ không vượt quá giá trị bất động sản"); return(PartialView(model)); } else { if (liabilities == null) { liabilities = new RealEstateLiabilityListCreateViewModel(); } else { if (liabilities.Liabilities.Count > 0) { id = liabilities.Liabilities.Max(x => x.Id) + 1; } else { id = 1; } } model.Id = id; liabilities.Liabilities.Add(model); HttpContext.Session["LIABILITIES"] = liabilities; return(Content("success")); } } else { return(PartialView(model)); } }
public ActionResult _LiabilityForm() { RealEstateLiabilityCreateViewModel model = new RealEstateLiabilityCreateViewModel(); return(PartialView(model)); }