/// <exception cref="UnknownPriorityException">Condition.</exception> /// <exception cref="TaskWithSameTitleExistsInProjectException">Condition.</exception> public void Handle(RegisterTask command) { var title = new Title(command.Title); var projectId = new ProjectId(command.ProjectId); TaskPriority priority; if (!TaskPriority.TryParse(command.Priority, out priority)) { throw new UnknownPriorityException(command.Priority); } Task task; if (command.Deadline.HasValue) { var deadline = new TaskDeadline(command.Deadline.Value); task = new Task(projectId, title, priority, deadline); } else { task = new Task(projectId, title, priority); } var query = new DoesTaskWithTitleAlreadyExistUnderSameProjectQuery(title, projectId); bool taskWithSameTitleExists = _taskQueryHandler.Handle(query); if (taskWithSameTitleExists) { throw new TaskWithSameTitleExistsInProjectException(); } _eventStoreRepository.Save(task); }
/// <exception cref="UnknownPriorityException"></exception> /// <exception cref="TaskDoesNotExistException">Condition.</exception> public void Handle(ReprioritizeTask command) { Task task = _eventStoreRepository.GetById(command.TaskId.ToString()); if (task == null) { throw new TaskDoesNotExistException(); } TaskPriority priority; if (TaskPriority.TryParse(command.Priority.ToLower(), out priority)) { task.Reprioritize(priority); _eventStoreRepository.Save(task); } else { throw new UnknownPriorityException(command.Priority); } }