public async Task UpdateSeriesAsync(int id, SeriesInputDto seriesDto) { var dbSeries = await _repository.GetByIdAsync(id).ConfigureAwait(true); if (dbSeries == null) { throw new NullReferenceException(); } _mapper.Map(seriesDto, dbSeries); dbSeries.Validate(); if (dbSeries.HasErrors) { throw new ValidationException(dbSeries.GetFirstError()); } await _repository.UpdateAsync(dbSeries).ConfigureAwait(true); }
public async Task AddSeriesAsync(SeriesInputDto seriesDto) { var series = _mapper.Map <Data.Series>(seriesDto); var publisher = await _publisherRepository.GetByIdAsync(seriesDto.PublisherId).ConfigureAwait(true); if (publisher == null) { throw new ValidationException("Invalid publisher id."); } series.Validate(); if (series.HasErrors) { throw new ValidationException(series.GetFirstError()); } await _repository.AddAsync(series).ConfigureAwait(true); }