public IActionResult Delete(int?id) { if (id != null && this.bagService.BagExists(id)) { EditBagModel editBagModel = this.bagService.GetBagCompleteEditInformation(id.Value); return(View(editBagModel)); } return(BadRequest()); }
public IActionResult Edit(EditBagModel editBagModel) { if (this.ModelState.IsValid && this.bagService.BagExists(editBagModel.BagId)) { this.bagService.EditBag(editBagModel); return(RedirectToAction("Index", "Home")); } return(View(editBagModel)); }
public void EditBag(EditBagModel editBagModel) { var bag = this.db.Bags.First(c => c.Id == editBagModel.BagId); bag.ImageUrl = editBagModel.ImageUrl; bag.Color = editBagModel.Color; bag.Description = editBagModel.Description; bag.Price = editBagModel.Price; bag.Quantity = editBagModel.Quantity; bag.Title = editBagModel.Title; this.db.SaveChanges(); }
public EditBagModel GetBagCompleteEditInformation(int bagId) { var bag = this.db.Bags.First(c => c.Id == bagId); EditBagModel editBagModel = new EditBagModel() { BagId = bag.Id, Description = bag.Description, Color = bag.Color, ImageUrl = bag.ImageUrl, Price = bag.Price, Quantity = bag.Quantity, Title = bag.Title }; return(editBagModel); }