public async Task <IActionResult> PutActor(string id, PutActorModel putActorModel)
        {
            try
            {
                if (!Guid.TryParse(id, out Guid actorId))
                {
                    throw new GuidException("Invalid id", this.GetType().Name, "PutActor", "400");
                }

                await _actorRepository.PutActor(id, putActorModel);

                return(NoContent());
            }
            catch (MovieMindException e)
            {
                if (e.MovieMindError.Status.Equals("404"))
                {
                    return(NotFound(e.MovieMindError));
                }
                else
                {
                    return(BadRequest(e.MovieMindError));
                }
            }
        }
        public async Task <IActionResult> Edit(string id)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Edit", "actor");

                GetActorModel getActorModel = await _moviemindAPIService.GetModel <GetActorModel>(id, "Actors");

                List <GetMovieModel> getMovieModels = await _moviemindAPIService.GetModels <GetMovieModel>("movies");

                ViewBag.Movies = getMovieModels;

                PutActorModel putDirectorModel = new PutActorModel
                {
                    FirstName   = getActorModel.FirstName,
                    LastName    = getActorModel.LastName,
                    Birth       = getActorModel.Birth,
                    Description = getActorModel.Description,
                    Nationality = getActorModel.Nationality,
                    Movies      = getActorModel.Movies
                };

                return(View(putDirectorModel));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e));
            }
        }
        [ValidateAntiForgeryToken] // Prevents XSRF/CSRF attacks
        public async Task <IActionResult> Edit(string id, PutActorModel putActorModel)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Edit", "actor");

                if (ModelState.IsValid)
                {
                    await _moviemindAPIService.PutModel <PutActorModel>(id, putActorModel, "Actors");

                    //delete (override) previous relationships
                    if (putActorModel.MovieIds != null)
                    {
                        List <GetActorMovieModel> getActorMovieModels = await _moviemindAPIService.GetModels <GetActorMovieModel>("ActorMovies");

                        List <GetActorMovieModel> getActorMovieModelsToDelete = getActorMovieModels.Where(x => x.ActorId == Guid.Parse(id)).ToList();

                        foreach (GetActorMovieModel getActorMovieModel in getActorMovieModelsToDelete)
                        {
                            await _moviemindAPIService.DeleteModel(getActorMovieModel.Id.ToString(), "ActorMovies");
                        }
                    }

                    //put in new relationships
                    foreach (Guid movieId in putActorModel.MovieIds)
                    {
                        await _moviemindAPIService.PostModel <PostActorMovieModel, GetActorMovieModel>(new PostActorMovieModel
                        {
                            ActorId = Guid.Parse(id),
                            MovieId = movieId
                        }, "ActorMovies");
                    }
                }

                return(Redirect("/Actors/Details/" + id));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e, this.View(putActorModel)));
            }
        }
        public async Task PutActor(string id, PutActorModel putActorModel)
        {
            try
            {
                Actor actor = await _context.Actors.FirstOrDefaultAsync(x => x.Id == Guid.Parse(id));

                actor.FirstName   = putActorModel.FirstName;
                actor.LastName    = putActorModel.LastName;
                actor.Birth       = putActorModel.Birth;
                actor.Nationality = putActorModel.Nationality;
                actor.Description = putActorModel.Description;

                await _context.SaveChangesAsync();
            }
            catch (MovieMindException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new DatabaseException(e.InnerException.Message, this.GetType().Name, "PutActor", "400");
            }
        }