public async Task <IActionResult> DeleteBoard(string userId, string boardId) { if (userId != User.FindFirst(ClaimTypes.NameIdentifier).Value) { return(Unauthorized()); } var board = await _repo.GetBoard(boardId); if (board == null) { return(BadRequest("Board not found")); } if (userId != board.OwnerId) { return(Unauthorized("Only board owner can delete the board")); } _repo.Remove(board); if (await _repo.SaveAll()) { return(NoContent()); } return(BadRequest("An error occurred during deletion. Please try again.")); }
public async Task <IActionResult> DeleteList(string userId, string boardId, string listId) { if (userId != User.FindFirst(ClaimTypes.NameIdentifier).Value) { return(Unauthorized()); } var currentUser = await _userManager.FindByIdAsync(userId); if (currentUser == null) { return(Unauthorized()); } var board = await _repo.GetBoard(boardId); if (board == null) { return(BadRequest("board not found, refresh the page.")); } if (!await _repo.UserInBoard(userId, boardId)) { return(Unauthorized()); } var list = await _repo.GetList(boardId, listId); if (list == null) { return(BadRequest("List not found or you can't delete that list.")); } _repo.Remove(list); foreach (var l in board.Lists) { if (l.Order > list.Order) { l.Order--; } } if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to delete the list.")); }
public async Task <IActionResult> DeleteCard([FromRoute] CardsControllerParamsDto paramsDto, string cardId) { if (paramsDto.UserId != User.FindFirst(ClaimTypes.NameIdentifier).Value) { return(Unauthorized()); } if (!await _repo.UserInBoard(paramsDto.UserId, paramsDto.BoardId)) { return(Unauthorized()); } var list = await _repo.GetList(paramsDto.BoardId, paramsDto.ListId); if (list == null) { return(BadRequest("board not found, refresh the page.")); } Card card = GetCard(list, cardId); if (card == null) { return(BadRequest("List not found or you can't delete that list.")); } _repo.Remove(card); foreach (var c in list.Cards) { if (c.Order > card.Order) { c.Order--; } } if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to delete the list.")); }