/// <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); }
public bool Handle(DoesTaskWithTitleAlreadyExistUnderSameProjectQuery query) { using (var session = _documentStore.OpenSession()) { bool doesTaskExist = session.Query <TaskInGridView>().Any(x => x.Title == query.Title); return(doesTaskExist); } }