Пример #1
0
        public ActionResult UpdateAlbumForBand(Guid bandId, Guid albumId,
                                               [FromBody] AlbumUpdateDTO album)
        {
            if (!_bandAlbumRepository.BandExists(bandId))
            {
                return(NotFound());
            }
            var albumFromRepository = _bandAlbumRepository.GetAlbum(bandId, albumId);

            if (albumFromRepository == null)
            {
                var albumEntity = _mapper.Map <Album>(album);
                albumEntity.Id = albumId;
                _bandAlbumRepository.AddAlbum(bandId, albumEntity);
                _bandAlbumRepository.Save();
                var albumReturn = _mapper.Map <AlbumDTO>(albumEntity);
                return(CreatedAtRoute("GetAlbum", new { bandId = bandId, albumId = albumReturn.Id }, albumReturn));
            }
            _mapper.Map(album, albumFromRepository);
            _bandAlbumRepository.UpdateAlbum(albumFromRepository);
            _bandAlbumRepository.Save();
            return(NoContent());
        }
Пример #2
0
        public async Task <ActionResult> PutAlbum(int id, [FromBody] AlbumUpdateDTO albumUpdateDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (albumUpdateDTO.Id != id)
            {
                return(BadRequest());
            }

            try
            {
                await _albumService.UpdateAlbumAsync(albumUpdateDTO, UserId);
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }

            return(Ok());
        }