public ActionResult Edit(int id = 0) { DiscountModel model = null; using (DiscountContext context = new DiscountContext()) { model = context.GetDiscount(id); ViewBag.DiscountKinds = context.GetDiscountKinds(); } return(View(model)); }
public ActionResult New() { DiscountModel model = new DiscountModel() { DiscountId = 0, Name = "", ValidFrom = DateTime.Now, ValidTo = DateTime.Now }; using (DiscountContext context = new DiscountContext()) { ViewBag.DiscountKinds = context.GetDiscountKinds(); } return(View("Edit", model)); }
public ActionResult Edit(DiscountModel model) { if (!ModelState.IsValid) { using (DiscountContext context = new DiscountContext()) { ViewBag.DiscountKinds = context.GetDiscountKinds(); } return(View("Edit", model)); } else { using (DiscountContext context = new DiscountContext()) { context.Edit(model); } return(RedirectToAction("Index")); } }