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);
     }
 }
Пример #2
0
        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));
        }
Пример #3
0
        public IHttpActionResult Put(GenreUpdate model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!_service.UpdateGenre(model))
            {
                return(InternalServerError());
            }
            return(Ok("Genre updated successfully! :^)"));
        }
Пример #4
0
        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));
        }