public static int UpdateCarLiability(CarLiabilityUpdateViewModel model) { Entities entities = new Entities(); var carLiability = entities.Liabilities.Where(x => x.Id == model.Id).FirstOrDefault(); carLiability.Name = model.Source; carLiability.Value = model.Value.Value; carLiability.OriginalValue = model.LiabilityValue.Value; carLiability.InterestType = model.InterestType; carLiability.InterestRatePerX = model.InterestRatePerX; carLiability.InterestRate = model.InterestRate.Value; carLiability.StartDate = model.StartDate.Value; carLiability.EndDate = model.EndDate.Value; carLiability.Note = model.Note; entities.Liabilities.Attach(carLiability); entities.Entry(carLiability).State = System.Data.Entity.EntityState.Modified; return(entities.SaveChanges()); }
public static CarLiabilityUpdateViewModel GetViewModelById(int id) { Entities entities = new Entities(); var carLiability = entities.Liabilities.Where(x => x.Id == id).FirstOrDefault(); CarLiabilityUpdateViewModel liabilityViewModel = new CarLiabilityUpdateViewModel(); liabilityViewModel.Id = carLiability.Id; liabilityViewModel.Source = carLiability.Name; liabilityViewModel.LiabilityValue = carLiability.OriginalValue; liabilityViewModel.Value = carLiability.Value; liabilityViewModel.InterestType = carLiability.InterestType.Value; liabilityViewModel.InterestRatePerX = carLiability.InterestRatePerX; liabilityViewModel.InterestRate = carLiability.InterestRate; liabilityViewModel.StartDate = carLiability.StartDate.Value; liabilityViewModel.EndDate = carLiability.EndDate.Value; liabilityViewModel.Note = carLiability.Note; return(liabilityViewModel); }
public ActionResult _CarLiabilityUpdateForm(CarLiabilityUpdateViewModel model) { if (model.Value > model.LiabilityValue) { ModelState.AddModelError("CheckValue", "Giá trị nợ phải nhỏ hơn tổng giá trị tiêu sản"); } if (ModelState.IsValid) { int result = CarLiabilityQueries.UpdateCarLiability(model); if (result > 0) { return(Content("success")); } else { return(Content("failed")); } } else { return(PartialView(model)); } }
public ActionResult _CarLiabilityUpdateForm(int id) { CarLiabilityUpdateViewModel model = CarLiabilityQueries.GetViewModelById(id); return(PartialView(model)); }