// update // GET: Toy/Edit/{id} public ActionResult Edit(int id) { var service = CreatedToysService(); var detail = service.GetToyById(id); var model = new ToyEdit { ToyId = detail.ToyId, Name = detail.Name, Brand = detail.Brand, Series = detail.Series, Artist = detail.Artist, Description = detail.Description, ReleaseYear = detail.ReleaseYear, RetailPrice = detail.RetailPrice }; return(View(model)); }
public bool UpdateToy(ToyEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Toys .Single(e => e.ToyId == model.ToyId && e.OwnerId == _userId); //.Single(e => e.ToyId == model.ToyId); entity.Name = model.Name; entity.Brand = model.Brand; entity.Series = model.Series; entity.Artist = model.Artist; entity.Description = model.Description; entity.ReleaseYear = model.ReleaseYear; entity.RetailPrice = model.RetailPrice; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, ToyEdit model) { //!did adding this break anything 1/27/21 -julia if (!ModelState.IsValid) { return(View(model)); } if (model.ToyId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreatedToysService(); if (service.UpdateToy(model)) { TempData["SaveResult"] = "This BLINYL was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "This blindbox/toy could not be updated."); return(View()); }