public ActionResult EditBudgetDetail(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var budgetDetailTmp = db.BudgetDetailTmps.Find(id); if (budgetDetailTmp == null) { return(HttpNotFound()); } var editBudgetDetailView = new EditBudgetDetailView { BudgetDetailTmpId = (int)id, Description = budgetDetailTmp.Description, Category = budgetDetailTmp.Category, Subcategory = budgetDetailTmp.Subcategory, Metered = budgetDetailTmp.Metered, UnitPrice = budgetDetailTmp.UnitPrice, Remarks = budgetDetailTmp.Remarks, }; return(PartialView(editBudgetDetailView)); }
public ActionResult EditBudgetDetail(EditBudgetDetailView editBudgetDetail) { if (ModelState.IsValid) { var budgetDetailTmp = db.BudgetDetailTmps.FirstOrDefault(odt => odt.UserName == User.Identity.Name && odt.BudgetDetailTmpId == editBudgetDetail.BudgetDetailTmpId); if (budgetDetailTmp != null) { budgetDetailTmp.UnitPrice = editBudgetDetail.UnitPrice; budgetDetailTmp.Metered = editBudgetDetail.Metered; budgetDetailTmp.PartialPrice = editBudgetDetail.UnitPrice * (decimal)editBudgetDetail.Metered; budgetDetailTmp.Remarks = editBudgetDetail.Remarks; db.Entry(budgetDetailTmp).State = EntityState.Modified; var responseSave = DBHelper.SaveChanges(db); if (responseSave.Succeeded) { return(RedirectToAction("Create")); } ModelState.AddModelError(string.Empty, responseSave.Message); } } return(PartialView(editBudgetDetail)); }