Beispiel #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);
        }
 public void MarkAsRead(int notificationId)
 {
     try
     {
         var notification = _context.Notifications.Find(notificationId);
         _context.Remove(notification);
         _context.SaveChanges();
     }
     catch (Exception e)
     {
     }
 }
        public async Task <(bool IsDone, string Message)> UpdateAsync(Guid userId, UpdatePoliciesModel model)
        {
            try
            {
                var user = await _context.Users.FindAsync(userId);

                var userAccess = await GetUserAccessAsync(user.Id, model.ProjectId);

                if (!userAccess[UserAction.CHANGE_SECURITY])
                {
                    return(IsDone : false, Message : "You don't have rights");
                }

                foreach (var projectUser in model.Users)
                {
                    var uId = _context.Users.SingleOrDefault(u => u.Email == projectUser.Email).Id;

                    foreach (var action in projectUser.Actions)
                    {
                        var oldPolicy = _context.ProjectSecurityPolicies
                                        .SingleOrDefault(x => x.UserId == uId && x.Action == (int)action.Action && x.ProjectSettingsId == model.ProjectId);
                        if (oldPolicy != null)
                        {
                            _context.Remove(oldPolicy);
                            await _context.SaveChangesAsync();
                        }

                        var policy = new ProjectSecurityPolicy
                        {
                            Action            = (int)action.Action,
                            IsAllowed         = action.Allowed,
                            UserId            = uId,
                            ProjectSettingsId = model.ProjectId
                        };
                        await _context.ProjectSecurityPolicies.AddAsync(policy);
                    }
                }

                await _context.SaveChangesAsync();

                return(IsDone : true, Message : "Success");
            }
            catch (Exception e)
            {
                _logger.LogError("SecurityService, UpdateAsync", e);
            }

            return(IsDone : false, Message : "Could not update security settings");
        }
Beispiel #4
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);
        }