示例#1
0
        public async Task <IActionResult> PostAsync([FromBody] SaveBoardResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var board  = _mapper.Map <SaveBoardResource, Board>(resource);
            var result = await _boardService.SaveAsync(board);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            var boardResource = _mapper.Map <Board, BoardMinimalResource>(result.Board);

            return(Ok(boardResource));
        }
示例#2
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] SaveBoardResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var email = HttpContext.User.Identity.Name;
            var board = _mapper.Map <SaveBoardResource, Board>(resource);

            var user = await _userService.FindByEmailAsync(email);

            var result = await _boardService.UpdateAsync(id, board, user);

            if (!result.Success)
            {
                return(BadRequest(new ErrorResource(result.Message)));
            }

            var boardResource = _mapper.Map <Board, BoardResource>(result.Board);

            return(Ok(boardResource));
        }