コード例 #1
0
        public async Task <LabelModel> CreateLabelAsync(LabelModel newLabel, string requestId)
        {
            if (!(await CheckAndSaveRequestIdAsync(requestId)))
            {
                throw new AlreadyHandledException();
            }

            try
            {
                newLabel.Init();

                var outboxMessage = OutboxMessageModel.Create(
                    new LabelCreatedUpdatedMessage
                {
                    LabelId = newLabel.Id,
                    Title   = newLabel.Title,
                    Color   = newLabel.Color
                }, Topics.Labels, MessageActions.Created);

                return(await _labelsRepository.CreateLabelAsync(newLabel, outboxMessage));
            }
            catch (Exception)
            {
                //rollback request id
                await _requestsRepository.DeleteRequestIdAsync(requestId);

                throw;
            }
        }
コード例 #2
0
        public async Task <ProjectModel> CreateProjectAsync(ProjectModel newProject, string requestId)
        {
            if (!(await CheckAndSaveRequestIdAsync(requestId)))
            {
                throw new AlreadyHandledException();
            }

            try
            {
                newProject.Init();

                var outboxMessage = OutboxMessageModel.Create(
                    new ProjectCreatedUpdatedMessage
                {
                    ProjectId = newProject.Id,
                    Title     = newProject.Title
                }, Topics.Projects, MessageActions.Created);

                return(await _projectsRepository.CreateProjectAsync(newProject, outboxMessage));
            }
            catch (Exception)
            {
                //rollback request id
                await _requestsRepository.DeleteRequestIdAsync(requestId);

                throw;
            }
        }
コード例 #3
0
        public async Task <TaskAggregate> CreateTaskAsync(TaskModel newTask,
                                                          IEnumerable <string> usersIds, IEnumerable <string> labelsIds, string requestId)
        {
            if (!(await CheckAndSaveRequestIdAsync(requestId)))
            {
                throw new AlreadyHandledException();
            }

            try
            {
                newTask.Init();

                TaskRelatedData taskData = await GetAndCheckTaskRelatedDataAsync(newTask, usersIds, labelsIds);

                var list = taskData.List;

                var taskCollections = new TaskCollections
                {
                    Members = usersIds,
                    Labels  = labelsIds
                };

                var membersRecords = _mapper.Map <IEnumerable <UserModel>, IEnumerable <TaskUserRecord> >(taskData.Users);
                var labelsRecords  = _mapper.Map <IEnumerable <LabelModel>, IEnumerable <TaskLabelRecord> >(taskData.Labels);

                var outboxMessage = OutboxMessageModel.Create(
                    new TaskCreatedMessage
                {
                    TaskId       = newTask.Id,
                    Title        = newTask.Title,
                    ProjectId    = list.ProjectId,
                    ProjectTitle = list.ProjectTitle,
                    ListId       = list.Id,
                    ListTitle    = list.Title,
                    Members      = membersRecords,
                    Labels       = labelsRecords
                }, Topics.Tasks, MessageActions.Created);

                var createdTask = await _tasksRepository.CreateTaskAsync(newTask, taskCollections, outboxMessage);

                List <Task> cacheInvalidationTasks = new List <Task>();
                foreach (var user in usersIds)
                {
                    string userCacheKey = string.Format(CacheSettings.UserTasksCacheKeyPattern, user);
                    cacheInvalidationTasks.Add(_cache.RemoveAsync(userCacheKey));
                }

                await Task.WhenAll(cacheInvalidationTasks);

                return(createdTask);
            }
            catch (Exception)
            {
                //rollback request id
                await _requestsRepository.DeleteRequestIdAsync(requestId);

                throw;
            }
        }
コード例 #4
0
        public async Task <TaskAggregate> CreateTaskAsync(TaskModel newTask,
                                                          IEnumerable <string> usersIds, IEnumerable <string> labelsIds, string requestId)
        {
            if (!(await CheckAndSaveRequestIdAsync(requestId)))
            {
                throw new AlreadyHandledException();
            }

            try
            {
                newTask.Init();

                TaskRelatedData taskData = await GetAndCheckTaskRelatedDataAsync(newTask, usersIds, labelsIds);

                var list = taskData.List;

                var taskCollections = new TaskCollections
                {
                    Members = usersIds,
                    Labels  = labelsIds
                };

                var membersRecords = _mapper.Map <IEnumerable <UserModel>, IEnumerable <TaskUserRecord> >(taskData.Users);
                var labelsRecords  = _mapper.Map <IEnumerable <LabelModel>, IEnumerable <TaskLabelRecord> >(taskData.Labels);

                var outboxMessage = OutboxMessageModel.Create(
                    new TaskCreatedMessage
                {
                    TaskId       = newTask.Id,
                    Title        = newTask.Title,
                    ProjectId    = list.ProjectId,
                    ProjectTitle = list.ProjectTitle,
                    ListId       = list.Id,
                    ListTitle    = list.Title,
                    Members      = membersRecords,
                    Labels       = labelsRecords
                }, Topics.Tasks, MessageActions.Created);

                return(await _tasksRepository.CreateTaskAsync(newTask, taskCollections, outboxMessage));
            }
            catch (Exception)
            {
                //rollback request id
                await _requestsRepository.DeleteRequestIdAsync(requestId);

                throw;
            }
        }
コード例 #5
0
        public async Task AddMemberToProjectAsync(ProjectMemberModel newProjectMember, string requestId)
        {
            if (!(await CheckAndSaveRequestIdAsync(requestId)))
            {
                throw new AlreadyHandledException();
            }

            (string projectTitle, string username) = await EnsureProjectAndUserExistAsync(newProjectMember.ProjectId, newProjectMember.UserId);

            try
            {
                var existingMember = await _projectMembersRepository.GetProjectMemberAsync(newProjectMember.ProjectId, newProjectMember.UserId);

                if (existingMember != null)
                {
                    throw new EntityExistsException("This member already in project");
                }

                var outboxMessage = OutboxMessageModel.Create(
                    new ProjectMemberCreatedUpdatedMessage
                {
                    ProjectId    = newProjectMember.ProjectId,
                    ProjectTitle = projectTitle,
                    UserId       = newProjectMember.UserId,
                    Username     = username,
                    Role         = newProjectMember.Role
                }, Topics.ProjectMembers, MessageActions.Created
                    );

                await _projectMembersRepository.AddMemberToProjectAsync(newProjectMember, outboxMessage);
            }
            catch (Exception)
            {
                //rollback request id
                await _requestsRepository.DeleteRequestIdAsync(requestId);

                throw;
            }
        }
コード例 #6
0
        public async Task <ListProjectAggregate> CreateListAsync(ListModel newList, string requestId)
        {
            if (!(await CheckAndSaveRequestIdAsync(requestId)))
            {
                throw new AlreadyHandledException();
            }

            try
            {
                var project = await _projectsRepository.GetProjectAsync(newList.ProjectId);

                if (project == null)
                {
                    throw new NotFoundException($"Project with id {newList.ProjectId} not found");
                }

                newList.Init();

                var outboxMessage = OutboxMessageModel.Create(
                    new ListCreatedMessage
                {
                    ListId    = newList.Id,
                    ProjectId = newList.ProjectId,
                    Title     = newList.Title
                }, Topics.Lists, MessageActions.Created);

                return(await _listsRepository.CreateListAsync(newList, outboxMessage));
            }
            catch (Exception)
            {
                //rollback request id
                await _requestsRepository.DeleteRequestIdAsync(requestId);

                throw;
            }
        }