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)); } }
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 })); }
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)); }
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))); }