Ejemplo n.º 1
0
        public GenericServiceResult MoveTask(string userId, int boardId, int taskId, int columnId)
        {
            try
            {
                bool isUserCanChangeTask = CanUserChangeTask(userId, boardId, taskId);
                if (!isUserCanChangeTask)
                {
                    return(GenericServiceResult.AccessDenied);
                }

                Task task = unitOfWork.Tasks.Get(taskId);
                task.ColumnId = columnId;
                unitOfWork.Tasks.Update(task);

                int     projectId = unitOfWork.Boards.Get(boardId).ProjectId;
                Project project   = unitOfWork.Projects.Get(projectId);
                Column  column    = unitOfWork.Columns.Get(columnId);

                NotificationMessage message = new NotificationMessage
                {
                    Title     = $"{project.Title}",
                    Message   = $"Task {task.Title} was moved to column {column.Title}",
                    Initiator = userId,
                    SendTo    = task.CreatorId
                };
                Notifyer.Notify(message);

                return(GenericServiceResult.Success);
            }
            catch
            {
                return(GenericServiceResult.Error);
            }
        }
Ejemplo n.º 2
0
        public async Task Invoke(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Invoked timercoinmarket");
            try
            {
                _logger.LogInformation(NoticeStore.NoticesCoinMarket.Count.ToString());
                _logger.LogInformation(CurrencyInfoStore.CoinMarkets.Count.ToString());

                NoticeStore.ClearCoinMarket();

                //_alertRepository.DeleteMany(x=> x.NotifyCost == null && string.IsNullOrEmpty(x.PercentNotify));

                var users = _userRepository.GetItems(z => z.NotifyCoinMarket).ToList(); //+

                var currencyPairs = await _client.GetCoinMarket();

                CurrencyInfoStore.AddCoinMarket(currencyPairs);

                var notifications = _currencyService
                                    .CreateNotifications(users, CurrencyInfoStore.CoinMarkets, 2, _alertRepository);

                await _notifyer.Notify(notifications);
            }
            catch (Exception e)
            {
                _logger.LogError("Timer coinmarket", e.Message);
            }
        }
Ejemplo n.º 3
0
        public GenericServiceResult RemoveUserFromProject(string userId, string userIdToRemove, int projectId)
        {
            try
            {
                bool canUserChangeProject = CanUserChangeProject(userId, projectId);
                if (!canUserChangeProject)
                {
                    return(GenericServiceResult.AccessDenied);
                }

                ProjectUser projectUser = unitOfWork.ProjectUser.GetFirstOrDefaultWhere(p => p.ProjectId == projectId && p.UserId == userIdToRemove);
                unitOfWork.ProjectUser.Delete(projectUser.Id);

                string projectTitle = unitOfWork.Projects.Get(projectId).Title;

                NotificationMessage message = new NotificationMessage
                {
                    Title     = $"{projectTitle}",
                    Message   = "You were removed from project.",
                    Link      = null,
                    ObjectId  = projectId,
                    Initiator = userId,
                    SendTo    = userIdToRemove
                };
                Notifyer.Notify(message);

                return(GenericServiceResult.Success);
            }
            catch
            {
                return(GenericServiceResult.Error);
            }
        }
Ejemplo n.º 4
0
        public async Task Invoke(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Invoked timerbittrex");
            try
            {
                _logger.LogInformation(NoticeStore.NoticesBittrix.Count.ToString());
                _logger.LogInformation(CurrencyInfoStore.Bittrixes.Count.ToString());

                NoticeStore.ClearBittrix();

                var users         = _userRepository.GetItems(x => x.NotifyBittrix).ToList();
                var currencyPairs = await _client.GetBittrix();

                CurrencyInfoStore.AddBittrix(currencyPairs);

                var notifications =
                    _currencyService.CreateNotifications(users, CurrencyInfoStore.Bittrixes, 0, _alertRepository);

                await _notifyer.Notify(notifications);
            }
            catch (Exception e)
            {
                _logger.LogError("Timer bittriex", e.Message);
            }
        }
Ejemplo n.º 5
0
        public GenericServiceResult UpdateBoardSettings(BoardSettingsViewModel model, string userId)
        {
            try
            {
                bool isUserCanChangeBoard = CanUserChangeBoard(userId, model.BoardId);

                if (!isUserCanChangeBoard)
                {
                    return(GenericServiceResult.AccessDenied);
                }

                Board         board         = unitOfWork.Boards.Get(model.BoardId);
                BoardSettings boardSettings = unitOfWork.BoardSettings.Get(model.BoardId);

                board.Title = model.Title;
                boardSettings.AccessToChangeBoard = (int)model.AccessToChangeBoard;
                boardSettings.AccessToChangeTask  = (int)model.AccessToChangeTask;
                boardSettings.AccessToCreateTask  = (int)model.AccessToCreateTask;
                boardSettings.AccessToDeleteTask  = (int)model.AccessToDeleteTask;

                unitOfWork.BoardSettings.Update(boardSettings);
                unitOfWork.Boards.Update(board);

                foreach (var column in model.Columns)
                {
                    Column databaseColumn = unitOfWork.Columns.Get(column.Id);
                    databaseColumn.Position = column.Position;
                    databaseColumn.Title    = column.Title;

                    unitOfWork.Columns.Update(databaseColumn);
                }

                int    projectId    = unitOfWork.Projects.Get(board.ProjectId).Id;
                string creatorId    = unitOfWork.ProjectUser.GetFirstOrDefaultWhere(p => p.ProjectId == projectId && p.Role == (int)ProjectRoles.Administrator).UserId;
                string projectTitle = unitOfWork.Projects.Get(projectId).Title;

                NotificationMessage message = new NotificationMessage
                {
                    Title     = $"{projectTitle}",
                    Message   = $"Board {board.Title} settings were changed",
                    Initiator = userId,
                    SendTo    = creatorId
                };
                Notifyer.Notify(message);

                return(GenericServiceResult.Success);
            }
            catch
            {
                return(GenericServiceResult.Error);
            }
        }
Ejemplo n.º 6
0
        public GenericServiceResult AddUserToProject(string userId, string userEmailToAdd, int projectId)
        {
            try
            {
                bool canUserChangeProject = CanUserChangeProject(userId, projectId);
                if (!canUserChangeProject)
                {
                    return(GenericServiceResult.AccessDenied);
                }

                User existingUser = unitOfWork.Users.GetFirstOrDefaultWhere(u => u.Email == userEmailToAdd);
                if (existingUser == null)
                {
                    return(GenericServiceResult.Error);
                }

                string userIdToAdd = existingUser.Id;

                ProjectUser existingProjectUser = unitOfWork.ProjectUser.GetFirstOrDefaultWhere(p => p.UserId == userIdToAdd && p.ProjectId == projectId);
                if (existingProjectUser != null)
                {
                    return(GenericServiceResult.Error);
                }

                ProjectUser projectUser = new ProjectUser
                {
                    ProjectId = projectId,
                    UserId    = userIdToAdd,
                    Role      = (int)ProjectRoles.Member
                };

                string projectTitle = unitOfWork.Projects.Get(projectId).Title;
                unitOfWork.ProjectUser.Create(projectUser);

                NotificationMessage message = new NotificationMessage
                {
                    Title     = $"{projectTitle}",
                    Message   = "You were added to project.",
                    Link      = null,
                    ObjectId  = projectId,
                    Initiator = userId,
                    SendTo    = userIdToAdd
                };
                Notifyer.Notify(message);

                return(GenericServiceResult.Success);
            }
            catch
            {
                return(GenericServiceResult.Error);
            }
        }
Ejemplo n.º 7
0
        public GenericServiceResult CreateBoard(CreateBoardViewModel model, string userId, int projectId)
        {
            try
            {
                bool isUserCanCreateBoard = CanUserCreateBoard(userId, projectId);

                if (!isUserCanCreateBoard)
                {
                    return(GenericServiceResult.AccessDenied);
                }

                ProjectUser projectUser = unitOfWork.ProjectUser.GetFirstOrDefaultWhere(p => p.ProjectId == projectId && p.UserId == userId);

                BoardSettings boardSettings = new BoardSettings
                {
                    AccessToChangeTask  = (int)model.AccessToChangeTask,
                    AccessToCreateTask  = (int)model.AccessToCreateTask,
                    AccessToDeleteTask  = (int)model.AccessToDeleteTask,
                    AccessToChangeBoard = (int)model.AccessToChangeBoard
                };

                Board board = new Board
                {
                    Title     = model.Title,
                    Settings  = boardSettings,
                    ProjectId = projectId,
                    CreatorId = userId
                };

                unitOfWork.Boards.Create(board);

                string creatorId    = unitOfWork.ProjectUser.GetFirstOrDefaultWhere(p => p.ProjectId == projectId && p.Role == (int)ProjectRoles.Administrator).UserId;
                string projectTitle = unitOfWork.Projects.Get(projectId).Title;

                NotificationMessage message = new NotificationMessage
                {
                    Title     = $"{projectTitle}",
                    Message   = $"Board {board.Title} was created",
                    Initiator = userId,
                    SendTo    = creatorId
                };
                Notifyer.Notify(message);

                return(GenericServiceResult.Success);
            }
            catch
            {
                return(GenericServiceResult.Error);
            }
        }
Ejemplo n.º 8
0
        public GenericServiceResult DeleteTask(string userId, int taskId, int boardId)
        {
            try
            {
                bool isUserCanDeleteTask = CanUserDeleteTask(userId, boardId, taskId);
                if (!isUserCanDeleteTask)
                {
                    return(GenericServiceResult.AccessDenied);
                }

                string taskTitle    = unitOfWork.Tasks.Get(taskId).Title;
                string taskCreator  = unitOfWork.Tasks.Get(taskId).CreatorId;
                string taskAssignee = unitOfWork.Tasks.Get(taskId).AssigneeId;

                unitOfWork.Attachments.Delete(a => a.TaskId == taskId);
                unitOfWork.Tasks.Delete(taskId);

                int     projectId = unitOfWork.Boards.Get(boardId).ProjectId;
                Project project   = unitOfWork.Projects.Get(projectId);

                NotificationMessage message = new NotificationMessage
                {
                    Title                   = $"{project.Title}",
                    Message                 = $"Task {taskTitle} was deleted",
                    Initiator               = userId,
                    SendTo                  = taskCreator,
                    AdditionalSendTo        = taskAssignee,
                    AdditionalSendToMessage = new NotificationMessage
                    {
                        Title     = $"{project.Title}",
                        Message   = $"Task {taskTitle} was deleted",
                        Initiator = userId,
                        SendTo    = taskAssignee,
                    }
                };
                Notifyer.Notify(message);

                return(GenericServiceResult.Success);
            }
            catch
            {
                return(GenericServiceResult.Error);
            }
        }
Ejemplo n.º 9
0
        public GenericServiceResult SaveProjectSettings(string userId, ProjectSettingsViewModel model)
        {
            try
            {
                int  projectId            = model.Id;
                bool canUserChangeProject = CanUserChangeProject(userId, projectId);
                if (!canUserChangeProject)
                {
                    return(GenericServiceResult.AccessDenied);
                }

                Project         project = unitOfWork.Projects.Get(projectId);
                string          projectTitleBeforeChanging = project.Title;
                ProjectSettings projectSettings            = unitOfWork.ProjectSettings.Get(projectId);

                project.Title = model.Title;
                project.About = model.About;
                projectSettings.AccessToChangeProject = (int)model.AccessToChangeProject;
                projectSettings.AccessToCreateBoard   = (int)model.AccessToCreateBoard;
                projectSettings.AccessToDeleteBoard   = (int)model.AccessToDeleteBoard;

                unitOfWork.ProjectSettings.Update(projectSettings);
                unitOfWork.Projects.Update(project);

                string creatorId            = unitOfWork.ProjectUser.GetFirstOrDefaultWhere(p => p.ProjectId == projectId && p.Role == (int)ProjectRoles.Administrator).UserId;
                NotificationMessage message = new NotificationMessage
                {
                    Title     = $"{projectTitleBeforeChanging}",
                    Message   = "Project settings were updated.",
                    Link      = null,
                    ObjectId  = projectId,
                    Initiator = userId,
                    SendTo    = creatorId
                };
                Notifyer.Notify(message);

                return(GenericServiceResult.Success);
            }
            catch
            {
                return(GenericServiceResult.Error);
            }
        }
Ejemplo n.º 10
0
        public GenericServiceResult DeleteBoard(string userId, int boardId)
        {
            try
            {
                Board board                = unitOfWork.Boards.Get(boardId);
                int   projectId            = board.ProjectId;
                bool  isUserCanDeleteBoard = CanUserDeleteBoard(userId, projectId);

                if (!isUserCanDeleteBoard)
                {
                    return(GenericServiceResult.AccessDenied);
                }

                var result = DeleteColumnsWithoutPermission(boardId);

                if (result != GenericServiceResult.Success)
                {
                    return(GenericServiceResult.Error);
                }

                unitOfWork.BoardSettings.Delete(board.Id);
                unitOfWork.Boards.Delete(board.Id);

                string creatorId    = unitOfWork.ProjectUser.GetFirstOrDefaultWhere(p => p.ProjectId == projectId && p.Role == (int)ProjectRoles.Administrator).UserId;
                string projectTitle = unitOfWork.Projects.Get(projectId).Title;

                NotificationMessage message = new NotificationMessage
                {
                    Title     = $"{projectTitle}",
                    Message   = $"Board {board.Title} was deleted",
                    Initiator = userId,
                    SendTo    = creatorId
                };
                Notifyer.Notify(message);

                return(GenericServiceResult.Success);
            }
            catch
            {
                return(GenericServiceResult.Error);
            }
        }
Ejemplo n.º 11
0
        public GenericServiceResult UpdateTask(TaskViewModel model, string userId)
        {
            try
            {
                bool isUserCanChangeTask = CanUserChangeTask(userId, model.BoardId, model.TaskId);
                if (!isUserCanChangeTask)
                {
                    return(GenericServiceResult.AccessDenied);
                }

                string creatorId = unitOfWork.Users.GetFirstOrDefaultWhere(u => u.Email == model.CreatorEmail).Id;
                string assigneId = null;
                if (model.AssigneeEmail != null)
                {
                    assigneId = unitOfWork.Users.GetFirstOrDefaultWhere(u => u.Email == model.AssigneeEmail).Id;
                }

                if (model.AssigneeId != null)
                {
                    assigneId = model.AssigneeId;
                }

                Task task = unitOfWork.Tasks.Get(model.TaskId);

                string taskPreviousAssignee = task.AssigneeId;

                task.Id         = model.TaskId;
                task.Title      = model.Title;
                task.Content    = model.Content;
                task.Priority   = (int)model.Priority;
                task.Severity   = (int)model.Severity;
                task.Type       = (int)model.Type;
                task.ColumnId   = model.ColumnId;
                task.AssigneeId = assigneId;
                task.CreatorId  = creatorId;

                string taskNewAssingee = taskPreviousAssignee == task.AssigneeId ? "" : task.AssigneeId;

                unitOfWork.Tasks.Update(task);

                Project project = unitOfWork.Projects.Get(model.ProjectId);

                NotificationMessage message = new NotificationMessage
                {
                    Title                   = $"{project.Title}",
                    Message                 = $"Task {task.Title} was changed",
                    Initiator               = "",
                    SendTo                  = task.CreatorId,
                    AdditionalSendTo        = taskNewAssingee,
                    AdditionalSendToMessage = new NotificationMessage
                    {
                        Title                   = $"{project.Title}",
                        Message                 = $"You were assigned to task {task.Title}",
                        Initiator               = userId,
                        SendTo                  = taskNewAssingee,
                        AdditionalSendTo        = taskPreviousAssignee,
                        AdditionalSendToMessage = new NotificationMessage
                        {
                            Title     = $"{project.Title}",
                            Message   = $"You were unassigned from task {task.Title}",
                            Initiator = userId,
                            SendTo    = taskPreviousAssignee
                        }
                    }
                };
                Notifyer.Notify(message);

                return(GenericServiceResult.Success);
            }
            catch
            {
                return(GenericServiceResult.Error);
            }
        }
Ejemplo n.º 12
0
        public GenericServiceResult CreateTask(CreateTaskViewModel model, string userId)
        {
            try
            {
                bool isUserCanCreateTask = CanUserCreateTask(userId, model.BoardId);
                if (!isUserCanCreateTask)
                {
                    return(GenericServiceResult.AccessDenied);
                }

                Task task = new Task
                {
                    ColumnId   = model.ColumnId,
                    Title      = model.Title,
                    Content    = model.Content,
                    Priority   = (int)model.Priority,
                    Severity   = (int)model.Severity,
                    Type       = (int)model.Type,
                    StartTime  = DateTime.Now,
                    AssigneeId = model.AssigneeId,
                    CreatorId  = userId
                };

                unitOfWork.Tasks.Create(task);
                int taskId = task.Id;

                GenericServiceResult result = UploadAttachment(taskId, model.Attachments);

                string creatorId    = unitOfWork.ProjectUser.GetFirstOrDefaultWhere(p => p.ProjectId == model.ProjectId && p.Role == (int)ProjectRoles.Administrator).UserId;
                string projectTitle = unitOfWork.Projects.Get(model.ProjectId).Title;

                NotificationMessage message = new NotificationMessage
                {
                    NotificationType = NotificationType.Changed,
                    Title            = $"{projectTitle}",
                    Message          = $"Task {task.Title} was created",
                    Initiator        = userId,
                    SendTo           = creatorId
                };
                Notifyer.Notify(message);

                if (task.AssigneeId != null)
                {
                    message = new NotificationMessage
                    {
                        NotificationType = NotificationType.Assigned,
                        Title            = $"{projectTitle}",
                        Message          = $"You were assigned to task {task.Title}",
                        Initiator        = userId,
                        SendTo           = task.AssigneeId
                    };
                    Notifyer.Notify(message);
                }

                return(GenericServiceResult.Success);
            }
            catch
            {
                return(GenericServiceResult.Error);
            }
        }