コード例 #1
0
        public async Task <IActionResult> UpdateBoard(string userId, BoardForUpdateDto boardForUpdate)
        {
            if (userId != User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                return(Unauthorized());
            }

            var board = await _repo.GetBoard(boardForUpdate.BoardId);

            if (board == null)
            {
                return(BadRequest("Board not found or You don't have access to that board."));
            }

            if (board.OwnerId != userId)
            {
                return(Unauthorized());
            }

            if (await _repo.UserInBoard(userId, boardForUpdate.BoardId))
            {
                _mapper.Map(boardForUpdate, board);
            }

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating board {boardForUpdate.BoardId} failed on save");
        }
コード例 #2
0
        public async Task <IActionResult> Put([FromBody] BoardForUpdateDto boardForUpdate)
        {
            // Validate id, return appropriate error response code if invalid
            var id    = boardForUpdate.BoardId;
            var board = new Board()
            {
                // Map the Dto boardForUpdate to board by assigning properties
                // Add/delete other members by assigning userIds in the list BoardMemberIds
            };

            await _unitOfWork.Boards.UpdateAsync(id, board);

            await _unitOfWork.SaveChangesAsync();

            return(Ok());
        }