public async Task <ActionResult <AlbumDTO> > PostAlbum([FromBody] AlbumAddDTO albumAddDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (albumAddDTO.UserId != UserId) { return(BadRequest()); } AlbumDTO albumDTO; try { albumDTO = await _albumService.AddAlbumAsync(albumAddDTO); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok(albumDTO)); }
public async Task <ActionResult> Post([FromBody] CreateAlbumDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var username = User.FindFirst(c => c.Type == ClaimTypes.Name).Value; var album = await _albumService.AddAlbumAsync(username, model); return(Created("api/album/" + album.Id, null)); }
public async Task <ActionResult <AlbumDTO> > Post([FromBody] AlbumDTO albumDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await albumService.AddAlbumAsync(albumDTO); albumDTO = await albumService.GetAlbumAsync(albumDTO.Name, albumDTO.Author); return(CreatedAtAction(nameof(Get), new { id = albumDTO.Id }, albumDTO)); }
// POST: api/Albums public async Task <Result <AlbumDto> > Post([FromBody] Album album) { return(await _albumService.AddAlbumAsync(album)); }
public async Task <ActionResult <AlbumModel> > PostAlbum([FromBody] AlbumAddModel albumAddModel) { var albumAddDTO = mapper.Map <AlbumAddDTO>(albumAddModel, opt => opt.Items["userId"] = UserId); return(Ok(mapper.Map <AlbumModel>(await albumService.AddAlbumAsync(albumAddDTO)))); }