public bool UpdateGenre(GenreUpdate model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Genres.Single(e => e.GenreId == model.GenreId); entity.GenreName = model.GenreName; return(ctx.SaveChanges() == 1); } }
public ActionResult Update(int id) { var _service = CreateGenreService(); var detail = _service.GetGenreById(id); var model = new GenreUpdate { GenreId = detail.GenreId, GenreName = detail.GenreName, }; return(View(model)); }
public IHttpActionResult Put(GenreUpdate model) { if (!ModelState.IsValid) { return(BadRequest()); } if (!_service.UpdateGenre(model)) { return(InternalServerError()); } return(Ok("Genre updated successfully! :^)")); }
public ActionResult Update(int id, GenreUpdate model) { if (!ModelState.IsValid) { return(View(model)); } if (model.GenreId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var _service = CreateGenreService(); if (_service.UpdateGenre(model)) { TempData["SaveResult"] = "Your Genre was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Genre could not be updated."); return(View(model)); }