[ValidateAntiForgeryToken] // Prevents XSRF/CSRF attacks public async Task <IActionResult> Create(PostActorModel postActorModel) { try { AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Create", "actor"); if (ModelState.IsValid) { GetActorModel getActorModel = await _moviemindAPIService.PostModel <PostActorModel, GetActorModel>(postActorModel, "Actors"); //put in new relationships foreach (Guid movieId in postActorModel.MovieIds) { await _moviemindAPIService.PostModel <PostActorMovieModel, GetActorMovieModel>(new PostActorMovieModel { ActorId = getActorModel.Id, MovieId = movieId }, "ActorMovies"); } return(Redirect("/Actors/Details/" + getActorModel.Id.ToString())); } return(View(postActorModel)); } catch (MovieMindException e) { return(ErrorHelper.HandleError(e, this.View(postActorModel))); } }
public async Task <GetActorModel> PostActor(PostActorModel postActorModel) { try { EntityEntry <Actor> result = await _context.Actors.AddAsync(new Actor { FirstName = postActorModel.FirstName, LastName = postActorModel.LastName, Birth = postActorModel.Birth, Nationality = postActorModel.Nationality, Description = postActorModel.Description }); await _context.SaveChangesAsync(); return(await GetActor(result.Entity.Id.ToString())); } catch (MovieMindException) { throw; } catch (Exception e) { throw new DatabaseException(e.InnerException.Message, this.GetType().Name, "PostActor", "400"); } }
public async Task <ActionResult <GetActorModel> > PostActor(PostActorModel postActorModel) { try { GetActorModel actor = await _actorRepository.PostActor(postActorModel); return(CreatedAtAction(nameof(GetActor), new { id = actor.Id }, actor)); } catch (DatabaseException e) { return(BadRequest(e.MovieMindError)); } }