public async Task <IActionResult> PutGenre(string id, PutGenreModel putGenreModel) { try { if (!Guid.TryParse(id, out Guid genreId)) { throw new GuidException("Invalid id", this.GetType().Name, "PutGenre", "400"); } await _genreRepository.PutGenre(id, putGenreModel); return(NoContent()); } catch (MovieMindException e) { if (e.MovieMindError.Status.Equals("404")) { return(NotFound(e.MovieMindError)); } else { return(BadRequest(e.MovieMindError)); } } }
[ValidateAntiForgeryToken] // Prevents XSRF/CSRF attacks public async Task <IActionResult> Edit(string id, PutGenreModel putGenreModel) { try { AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Edit", "genre"); if (ModelState.IsValid) { await _moviemindAPIService.PutModel <PutGenreModel>(id, putGenreModel, "Genres"); return(RedirectToRoute(new { action = "Index", controller = "Genres" })); } return(View(putGenreModel)); } catch (MovieMindException e) { return(ErrorHelper.HandleError(e, this.View(putGenreModel))); } }
public async Task <IActionResult> Edit(string id) { try { AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Edit", "genre"); GetGenreModel getGenreModel = await _moviemindAPIService.GetModel <GetGenreModel>(id, "Genres"); PutGenreModel putGenreModel = new PutGenreModel { Name = getGenreModel.Name }; return(View(putGenreModel)); } catch (MovieMindException e) { return(ErrorHelper.HandleError(e)); } }
public async Task PutGenre(string id, PutGenreModel putGenreModel) { Genre genre = await _context.Genres.FirstOrDefaultAsync(x => x.Id == Guid.Parse(id)); if (genre == null) { throw new EntityException("Genre not found", this.GetType().Name, "PutGenre", "404"); } try { genre.Name = putGenreModel.Name; await _context.SaveChangesAsync(); } catch (MovieMindException) { throw; } catch (Exception e) { throw new DatabaseException(e.InnerException.Message, this.GetType().Name, "PutGenre", "400"); } }