예제 #1
0
        public async Task UpdateStatusAsync(int userId, int taskId, TaskStatus status)
        {
            if (!await _projectsDataAccessor.IsProjectCreatorByTaskId(userId, taskId) &&
                !await _permissionsDataAccessor.HasPermissionForTask(userId, taskId))
            {
                throw new NoPermissionsForOperationException(ErrorMessages.NoPermissionsForOperation);
            }

            var task = await _taskDataAccessor.UpdateStatusAsync(taskId, status);

            using (_connectionContext.EventScope())
            {
                _taskEventAccessor.StatusUpdated(task, await _projectsDataAccessor.GetAsync(taskId));
            }
        }
예제 #2
0
 public Task AddTaskToUser(int userId, int taskId, TaskStatus status, ITaskInfo taskInfo)
 {
     return(_context.Users.UpdateOneAsync(x => x.UserId == userId && !x.Tasks.Any(y => y.Id == taskId),
                                          Builders <UserEntity> .Update.Push(x => x.Tasks, new TaskEntity
     {
         Id = taskId,
         Added = taskInfo.Added,
         TimeToComplete = taskInfo.TimeToComplete,
         FeatureId = taskInfo.FeatureId,
         Name = taskInfo.Name,
         Description = taskInfo.Description,
         Priority = taskInfo.Priority,
         Status = status
     }), new UpdateOptions {
         IsUpsert = true
     }));
 }
예제 #3
0
        public async Task <ITask> UpdateStatusAsync(int taskId, TaskStatus status)
        {
            var context = _contextStorage.Get();
            var task    = await context.Tasks.FirstOrDefaultAsync(x => x.Id == taskId);

            if (task != null)
            {
                switch (status)
                {
                case TaskStatus.Completed:
                    if (task.Status != TaskStatus.Active)
                    {
                        throw new InvalidArgumentException(ErrorMessages.Tasks_CompleteUnactive);
                    }
                    task.Status = status;
                    await context.SaveChangesAsync();

                    return(task);

                case TaskStatus.Removed:
                    if (task.Status != TaskStatus.Completed)
                    {
                        throw new InvalidArgumentException(ErrorMessages.Tasks_RemoveUncompleted);
                    }
                    task.Status = status;
                    await context.SaveChangesAsync();

                    return(task);

                default:
                    throw new InvalidArgumentException(ErrorMessages.Tasks_InvalidStatusParameterValue);
                }
            }

            throw new NotFoundException(String.Format(ErrorMessages.Tasks_NotFound, taskId));
        }
예제 #4
0
 public Task ChangeTaskStatus(int userId, int taskId, TaskStatus status)
 {
     return(_context.Users.UpdateOneAsync(x => x.UserId == userId && x.Tasks.Any(t => t.Id == taskId),
                                          Builders <UserEntity> .Update.Set("Tasks.$.Status", status)));
 }