예제 #1
0
        public OperationResult <IWorkTask> CreateTask(ITasksGroup tasksGroup, string description, IWorkTaskProducer workTaskProducer)
        {
            if (workTaskProducer == null)
            {
                throw new ArgumentNullException(nameof(workTaskProducer));
            }

            IWorkTask createdTask = workTaskProducer.ProduceTask(mIDProducer.ProduceID(), description);

            OperationResult addTaskResult = tasksGroup.AddTask(createdTask);

            addTaskResult.Log(mLogger);

            if (!addTaskResult.Success)
            {
                return(new OperationResult <IWorkTask>(false, addTaskResult.Reason, createdTask));
            }

            return(new OperationResult <IWorkTask>(true, addTaskResult.Reason, createdTask));
        }
        public async Task <IResponse <IWorkTask> > MoveTaskAsync(string workTaskId, string tasksGroupId)
        {
            ITasksGroup destinationGroup = await mTasksGroupRepository.FindAsync(tasksGroupId).ConfigureAwait(false);

            if (destinationGroup == null)
            {
                return(new FailResponse <IWorkTask>($"Entity group {tasksGroupId} not found. No move performed"));
            }

            try
            {
                (ITasksGroup OldParentGroup, IWorkTask taskToMove) =
                    await FindWorkTaskAndItsParentGroup(workTaskId).ConfigureAwait(false);

                if (taskToMove != null)
                {
                    if (IsWorkTaskDescriptionAlreadyExist(destinationGroup, taskToMove.Description))
                    {
                        return(new FailResponse <IWorkTask>(
                                   $"Task description'{taskToMove.Description}' is already exist in group {destinationGroup.ID}"));
                    }

                    destinationGroup.AddTask(taskToMove);
                    await mTasksGroupRepository.UpdateAsync(destinationGroup).ConfigureAwait(false);

                    OldParentGroup.RemoveTask(taskToMove.ID);
                    await mTasksGroupRepository.UpdateAsync(OldParentGroup).ConfigureAwait(false);

                    return(new SuccessResponse <IWorkTask>(taskToMove));
                }

                return(new FailResponse <IWorkTask>($"Work task {workTaskId} not found. No task move performed"));
            }
            catch (Exception ex)
            {
                return(new FailResponse <IWorkTask>($"An error occurred when moving task id {workTaskId}: {ex.Message}"));
            }
        }