public ActionResult Edit([Bind(Include = "SupplyID,Provider.ProviderID,Product.ProductID,Quantity,Price,SupplyDate")] SupplyEdit supplyEdit) { if (ModelState.IsValid) { serviceSupplies.UpdateSupply(supplyEdit.ToSupply()); return(RedirectToAction("Index")); } return(View(supplyEdit)); }
// GET: SupplyViews/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SupplyEdit supplyEdit = new SupplyEdit(serviceSupplies.GetSupply(Convert.ToInt32(id)), serviceProducts.GetProducts(), serviceProviders.GetProviders()); if (supplyEdit == null) { return(HttpNotFound()); } return(View(supplyEdit)); }
public bool UpdateSupply(SupplyEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Items .Single(e => e.SupplyId == model.SupplyId && e.OwnerId == _ownerId); entity.SupplyName = model.SupplyName; entity.Brand = model.Brand; entity.Color = model.Color; entity.Quantity = model.Quantity; entity.TotalCost = model.TotalCost; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id) { var service = CreateSupplyService(); var detail = service.GetItemById(id); var model = new SupplyEdit { SupplyId = detail.SupplyId, SupplyName = detail.SupplyName, Brand = detail.Brand, Color = detail.Color, Quantity = detail.Quantity, TotalCost = detail.TotalCost, AlreadyHave = detail.AlreadyHave }; return(View(model)); }
public ActionResult Edit(int id, SupplyEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.SupplyId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateSupplyService(); if (service.UpdateSupply(model)) { TempData["SaveResult"] = ("Your supply was updated."); return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your supply could not be updated."); return(View(model)); }
// GET: SupplyViews/Create public ActionResult Create() { SupplyEdit supplyEdit = new SupplyEdit(serviceProducts.GetProducts(), serviceProviders.GetProviders()); return(View(supplyEdit)); }