Example #1
0
        public Task AddArtistAsync(ArtistDetailsDto artist)
        {
            var addArtist = _mapper.Map <Data.Artist>(artist);

            addArtist.Validate();

            if (addArtist.HasErrors)
            {
                throw new ValidationException(addArtist.GetFirstError());
            }

            return(_repository.AddAsync(addArtist));
        }
Example #2
0
        public async Task UpdateArtistAsync(int id, ArtistDetailsDto artist)
        {
            var dbArtist = await _repository.GetByIdAsync(id).ConfigureAwait(true);

            if (dbArtist == null)
            {
                throw new NullReferenceException();
            }

            _mapper.Map(artist, dbArtist);
            dbArtist.Validate();

            if (dbArtist.HasErrors)
            {
                throw new ValidationException(dbArtist.GetFirstError());
            }

            await _repository.UpdateAsync(dbArtist).ConfigureAwait(true);
        }