Ejemplo n.º 1
0
        public async Task <IActionResult> AddMovie([FromBody] MovieToBeRegisteredDto movieToBeRegisteredDto)
        {
            var contributor = await _movieRepo.GetContributor(movieToBeRegisteredDto.ContributorName);

            var movieToCreate = _mapper.Map <Movie>(movieToBeRegisteredDto);

            try
            {
                if (contributor == null)
                {
                    var contributorToBeAdded = new Contributor
                    {
                        Name        = movieToBeRegisteredDto.ContributorName,
                        Description = "I`m not sure what to put here",
                        Title       = " some title"
                    };

                    var addContributor = _movieRepo.AddContributor(contributorToBeAdded);
                    movieToCreate.Contributors.Add(addContributor);
                }


                var createdMovie = await _movieRepo.AddMovie(movieToCreate);

                return(CreatedAtRoute("GetMovie", new { controller = "Movie", id = movieToCreate.ID }, movieToCreate));
            }
            catch (Exception)
            {
                throw new Exception("Something terrible happened");
            }
        }