public ActionResult Create(Vegetable vegetable) { try { if (ModelState.IsValid) { ctx.Vegetables.Add(vegetable); ctx.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(vegetable)); } catch { return(View(vegetable)); } }
public ActionResult Create(Sale sale) { try { if (ModelState.IsValid) { ctx.Sales.Add(sale); ctx.SaveChanges(); return(RedirectToAction(nameof(Index))); } ViewBag.VegetableId = new SelectList(ctx.Vegetables, "Id", "Name"); return(View(sale)); } catch { return(View(sale)); } }
public ActionResult Edit(int id, Sale sale) { ViewBag.VegetableId = new SelectList(ctx.Vegetables, "Id", "Name"); Sale sales = ctx.Sales.SingleOrDefault(x => x.SaleId == id); try { if (sales != null) { sales.SaleDate = sale.SaleDate; sales.SaleWeight = sale.SaleWeight; sales.SaleUnitPrice = sale.SaleUnitPrice; sales.SaleActive = sale.SaleActive; ctx.SaveChanges(); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }