public ActionResult Edit(int id) { var service = CreateLarderService(); var detail = service.GetLarderbyId(id); var model = new LarderEdit { ID = detail.ID, Name = detail.Name, Description = detail.Description }; model.Season = new Data.Models.Season(); if (detail.Seasons.Contains("Spring")) { model.Season.Spring = true; } if (detail.Seasons.Contains("Summer")) { model.Season.Summer = true; } if (detail.Seasons.Contains("Winter")) { model.Season.Winter = true; } if (detail.Seasons.Contains("Fall")) { model.Season.Fall = true; } return(View(model)); }
public IHttpActionResult Put(LarderEdit larder) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateLarderService(); if (!service.UpdateLarder(larder)) { return(InternalServerError()); } return(Ok()); }
public bool UpdateLarder(LarderEdit model) { using (var context = new CookbookContext()) { var entity = context .Larders .Single(e => e.ID == model.ID && e.AuthorID == userId); entity.Name = model.Name; entity.Description = model.Description; entity.DateModified = DateTimeOffset.UtcNow; return(context.SaveChanges() == 1); } }
public ActionResult Edit(int id, LarderEdit model) { if (!ModelState.IsValid) { return(View(model)); } else if (model.ID != id) { ModelState.AddModelError("", "Id mismatch"); return(View(model)); } var service = CreateLarderService(); if (service.UpdateLarder(model)) { TempData["Save Result"] = "Your larder recipe was updated."; return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Your larder recipe could not be updated."); return(View(model)); } }