示例#1
0
        public async Task <bool> DeleteProjectAsync(Guid userId, int projectId)
        {
            try
            {
                var access = await _securityService.GetUserAccessAsync(userId, projectId);

                if (!access[UserAction.DELETE_PROJECT])
                {
                    return(false);
                }

                var project = await _context.Projects.FindAsync(projectId);

                if (project == null)
                {
                    return(false);
                }

                var boards = _context.Boards.Where(x => x.ProjectId == projectId);
                await boards.ForEachAsync(async x => await _taskService.DeleteBoardTasksAsync(userId, x.Id, projectId));

                _context.RemoveRange(boards);
                _context.Remove(project);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError("ProjectService: DeleteProjectAsync", e);
            }

            return(false);
        }
示例#2
0
        public async Task <bool> DeleteBoardTasksAsync(Guid userId, int boardId, int projectId)
        {
            try
            {
                var access = await _securityService.GetUserAccessAsync(userId, projectId);

                if (!access[UserAction.DELETE_BOARD])
                {
                    return(false);
                }

                var board = await _context.Boards.FindAsync(boardId);

                if (board == null)
                {
                    return(false);
                }

                var columns = _context.Columns.Where(x => x.BoardId == boardId);
                var tasks   = _context.Tasks.Where(x => columns.Select(c => c.Id).Contains(x.ColumnId));
                foreach (var task in tasks)
                {
                    await DeleteTaskAsync(userId, task.Id, projectId);
                }

                _context.RemoveRange(columns);
                _context.Remove(board);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError("TaskService: DeleteBoardTasksAsync", e);
            }

            return(false);
        }