示例#1
0
        public async Task <Film> AddGenreAsync(Film film, Genre genre)
        {
            try
            {
                var filmToUpdate = await filmRepository.GetByConditionAsync(s => s.Name == film.Name).ConfigureAwait(false);

                await filmValidator.ValidateAddGenreAsync(filmToUpdate, genre).ConfigureAwait(false);

                FilmWithGenre newAssocistion = new FilmWithGenre()
                {
                    Id      = Guid.NewGuid(),
                    Film    = film,
                    FilmId  = film.Id,
                    Genre   = genre,
                    GenreId = genre.Id
                };
                filmWithGenreRepo.Add(newAssocistion);
                filmRepository.Update(filmToUpdate);
                await filmRepository.SaveChangesAsync().ConfigureAwait(false);

                foreach (FilmWithGenre fwg in filmToUpdate.Genres)
                {
                    fwg.Genre = await genreRepository.GetAsync(fwg.GenreId).ConfigureAwait(false);
                }
                return(filmToUpdate);
            }
            catch (Exception e)
            {
                throw new BusinessLogicException(e.Message);
            }
        }
示例#2
0
        public async Task <IActionResult> PostAsync([FromBody] FilmDTO model)
        {
            await Task.Yield();

            try
            {
                var filmToCreate = model.ToEntity();
                filmToCreate.Director = await directorLogic.GetAsync(model.DirectorID).ConfigureAwait(false);

                filmToCreate.Genres = new List <FilmWithGenre>();
                FilmWithGenre fwg = new FilmWithGenre()
                {
                    GenreId = model.MainGenreID,
                    Genre   = await genreLogic.GetAsync(model.MainGenreID).ConfigureAwait(false),
                    Film    = filmToCreate,
                };
                filmToCreate.Genres.Add(fwg);

                var film = await filmLogic.CreateAsync(filmToCreate).ConfigureAwait(false);

                return(Ok(new FilmDTO(film)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
示例#3
0
 public GenreInFilmDTO(FilmWithGenre genre)
 {
     this.FilmId  = genre.FilmId;
     this.GenreId = genre.GenreId;
     this.Id      = genre.Id;
 }
示例#4
0
        public Film ToEntity()
        {
            var film = new Film()
            {
                Id             = this.Id,
                Name           = this.Name,
                Description    = this.Description,
                LaunchDate     = this.LaunchDate,
                AdditionDate   = this.AdditionDate,
                FilmScore      = this.Score,
                Ratings        = new List <Rating>(),
                Genres         = new List <FilmWithGenre>(),
                UserFavourites = new List <UserFavouriteFilm>()
            };

            if (this.Director != null)
            {
                film.Director = this.Director.ToEntity();
            }

            if (Ratings != null)
            {
                foreach (RatingDTO ratingDTO in this.Ratings)
                {
                    film.Ratings.Add(ratingDTO.ToEntity());
                }
            }

            if (Genres != null)
            {
                foreach (GenreDTO genreDTO in this.Genres)
                {
                    FilmWithGenre fwg = new FilmWithGenre()
                    {
                        Genre   = genreDTO.ToEntity(),
                        GenreId = genreDTO.Id,
                        Film    = film,
                        FilmId  = film.Id
                    };
                    film.Genres.Add(fwg);
                }
            }

            if (UserFavourites != null)
            {
                foreach (UserDTO userDTO in this.UserFavourites)
                {
                    UserFavouriteFilm uff = new UserFavouriteFilm()
                    {
                        User   = userDTO.ToEntity(),
                        UserId = userDTO.Id,
                        Film   = film,
                        FilmId = film.Id
                    };
                    film.UserFavourites.Add(uff);
                }
            }


            return(film);
        }