public async Task <ActionResult> UpdateAlbum(Guid albumId, [FromBody] AlbumPutRequest albumPutRequest) { if (!_albumRepository.AlbumExists(albumId)) { //TODO: Create new album //map source (albumPutRequest) to destination type <album> var albumToAdd = _mapper.Map <Album>(albumPutRequest); albumToAdd.Id = albumId; //call add _albumRepository.AddAlbum(albumToAdd); //call save await _albumRepository.SaveAsync(); //map source to AlbumGetResponse type var albumGetResponse = _mapper.Map <AlbumGetResponse>(albumToAdd); //create response and route return(CreatedAtRoute("GetAlbum", new { version = HttpContext.GetRequestedApiVersion().ToString(), artistId = albumGetResponse.Id }, albumGetResponse)); } //Get album from repo var albumFromRepo = await _albumRepository.GetAlbumAsync(albumId); //map source (albumPutRequest) to existing destination (albumFromRepo) _mapper.Map(albumPutRequest, albumFromRepo); //call update _albumRepository.UpdateAlbum(albumFromRepo); //call save await _albumRepository.SaveAsync(); return(NoContent()); }
public async Task <ActionResult <bool> > PutCustomer(AlbumPutRequest request) { return(Ok(await _repository.Update(_mapper.Map <Album>(request)))); }