コード例 #1
0
        public async Task <User> AddFavouriteAsync(UserFavouriteFilm favourite)
        {
            try
            {
                var userToUpdate = await userRepository.GetAsync(favourite.UserId).ConfigureAwait(false);

                var filmToFavourite = await filmRepository.GetAsync(favourite.FilmId).ConfigureAwait(false);

                await userValidator.ValidateAddFavouriteFilmAsync(userToUpdate, filmToFavourite);

                UserFavouriteFilm newAssocistion = new UserFavouriteFilm()
                {
                    Id     = Guid.NewGuid(),
                    Film   = filmToFavourite,
                    FilmId = filmToFavourite.Id,
                    User   = userToUpdate,
                    UserId = userToUpdate.Id
                };
                userFavouriteFilmRepo.Add(newAssocistion);
                userRepository.Update(userToUpdate);
                filmRepository.Update(filmToFavourite);
                await userRepository.SaveChangesAsync().ConfigureAwait(false);

                return(await userRepository.GetAsync(userToUpdate.Id).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                throw new BusinessLogicException(e.Message);
            }
        }