示例#1
0
        public async Task UpdateAsync(MovieUi movieUi)
        {
            var existedEntity = await _movieRepository.FindByAsync(e => e.Id == movieUi.Id);

            if (existedEntity == null)
            {
                throw new ArgumentException($"Movie with id : {movieUi.Id} not found");
            }

            if (movieUi.GenreId == Guid.Empty)
            {
                throw new ArgumentException($"Genre can't be null");
            }

            var existedGenre = await _movieGenreRepository.FindByAsync(e => e.Id == movieUi.GenreId);

            if (existedGenre == null)
            {
                throw new ArgumentException($"Genre with id : {movieUi.GenreId} not found");
            }

            existedEntity.GenreId = movieUi.GenreId;
            existedEntity.Title   = movieUi.Title;
            existedEntity.Year    = movieUi.Year;

            await _movieRepository.EditAsync(existedEntity);
        }