public async Task <ActionResult> Update(PostBoardViewModel model, int boardId) { bool boardExists = await _boardRepository.Exists(boardId); if (!boardExists) { return(V1NotFound("Board not found")); } int userId = int.Parse(HttpContext.User.Identity.Name); BoardMember member = await _memberRepository.GetByBoardIdAndUserId(boardId, userId); if (member is null || !member.IsAdmin) { return(Forbid()); } Board board = new Board { Id = boardId, Title = model.Title, ModifiedOn = _dateTimeProvider.UtcNow() }; await _boardRepository.Update(board); return(NoContent()); }
public async Task <ActionResult> Create( PostBoardMemberViewModel model, int boardId, [FromServices] IUserRepository userRepository) { bool boardExists = await _boardRepository.Exists(boardId); if (!boardExists) { return(V1NotFound("Board not found")); } int userId = int.Parse(HttpContext.User.Identity.Name); BoardMember userMember = await _memberRepository.GetByBoardIdAndUserId(boardId, userId); if (userMember is null || !userMember.IsAdmin) { return(Forbid()); } User newMemberUser = await userRepository.GetByEmailWithPassword(model.Email); if (newMemberUser is null) { return(V1NotFound("User not found")); } bool alreadyIsMember = await _memberRepository.GetByBoardIdAndUserId(boardId, newMemberUser.Id) is { }; if (alreadyIsMember) { return(NoContent()); } DateTime createdDate = _dateTimeProvider.UtcNow(); var member = new BoardMember { Board = new Board { Id = boardId }, User = new User { Id = newMemberUser.Id, }, IsAdmin = model.IsAdmin, CreatedOn = createdDate, ModifiedOn = createdDate }; await _memberRepository.Insert(member); return(NoContent()); }
public async Task <ActionResult> Create(int boardId, int taskId, int memberId) { bool boardExists = await _boardRepository.Exists(boardId); if (!boardExists) { return(V1NotFound("Board not found")); } int userId = int.Parse(HttpContext.User.Identity.Name); BoardMember userMember = await _memberRepository.GetByBoardIdAndUserId(boardId, userId); if (userMember is null) { return(Forbid()); } KanbanTask task = await _taskRepository.GetByIdAndBoardId(taskId, boardId); if (task is null) { return(V1NotFound("Task not found")); } BoardMember member = await _memberRepository.GetByBoardIdAndUserId(boardId, memberId); if (member is null) { return(V1NotFound("Member not found")); } bool existsAssignment = await _assignmentRepository.ExistsAssignment(taskId, member); if (!existsAssignment) { await _assignmentRepository.Insert(taskId, member); } return(NoContent()); }