예제 #1
0
        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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #4
0
 // POST: api/Albums
 public async Task <Result <AlbumDto> > Post([FromBody] Album album)
 {
     return(await _albumService.AddAlbumAsync(album));
 }
예제 #5
0
        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))));
        }