public TaskDTO UpdateTask(TodoContext context, UpdateTaskRequest updateTaskRequest) { _updateTaskRequestValidator.ValidateAndThrow(updateTaskRequest); var user = _authenticationService.GetUserBySessionToken( context, updateTaskRequest.SessionToken); var task = context.Tasks .Include("User") .SingleOrDefault(t => t.TaskId == updateTaskRequest.TaskId); if (task == null) { throw new TodoException(ServiceError.NoSuchTask); } if (task.UserId != user.UserId) { throw new TodoException(ServiceError.NoPermissions); } task.TaskDescription = updateTaskRequest.TaskDescription; task.ModifiedAt = _timeProvider.GetCurrentTime(); context.SaveChanges(); return(_taskToTaskDtoMapper.Map(task)); }
public TaskDTO UnprogressTask(TodoContext context, UnprogressTaskRequest unprogressTaskRequest) { _unprogressTaskRequestValidator.ValidateAndThrow(unprogressTaskRequest); var user = _authenticationService.GetUserBySessionToken( context, unprogressTaskRequest.SessionToken); var task = context.Tasks .Include("User") .SingleOrDefault(t => t.TaskId == unprogressTaskRequest.TaskId); if (task == null) { throw new TodoException(ServiceError.NoSuchTask); } if (task.UserId != user.UserId) { throw new TodoException(ServiceError.NoPermissions); } var newTaskStatus = _taskProgressLogic.GetPreviousFor((TaskStatus)task.TaskStatus); task.TaskStatus = (int)newTaskStatus; task.ModifiedAt = _timeProvider.GetCurrentTime(); context.SaveChanges(); return(_taskToTaskDtoMapper.Map(task)); }
public WorkspaceDTO GetWorkspace(TodoContext context, GetWorkspaceRequest getWorkspaceRequest) { _getWorkspaceRequestValidator.ValidateAndThrow(getWorkspaceRequest); var user = _authenticationService.GetUserBySessionToken( context, getWorkspaceRequest.SessionToken); Func <Task, bool> taskIsOwnedByUserAndIsNotComplete = task => task.UserId == user.UserId && task.TaskStatus != (int)TaskStatus.Complete; var tasks = context.Tasks.Where(taskIsOwnedByUserAndIsNotComplete).ToList(); return(new WorkspaceDTO { Tasks = _taskToTaskDtoMapper.Map(tasks) }); }
public TaskDTO CreateTask(TodoContext context, CreateTaskRequest createTaskRequest) { _createTaskRequestValidator.ValidateAndThrow(createTaskRequest); var user = _authenticationService.GetUserBySessionToken( context, createTaskRequest.SessionToken); var task = new Task { TaskStatus = (int)TaskStatus.NotStarted, TaskDescription = createTaskRequest.TaskDescription, CreatedAt = _timeProvider.GetCurrentTime(), ModifiedAt = null, User = user }; context.Tasks.Add(task); context.SaveChanges(); return(_taskToTaskDtoMapper.Map(task)); }