/// <exception cref="ProjectWithSameTitleExistsException">Condition.</exception> public void Handle(RegisterProject command) { var title = new Title(command.Title); Project project; if (command.Deadline.HasValue) { var deadline = new ProjectDeadline(command.Deadline.Value); project = new Project(title, deadline); } else { project = new Project(title); } var doesProjectWithTitleExistQuery = new DoesProjectWithTitleExistQuery(title); bool projectWithSameTitleExists = _projectQueryService.Handle(doesProjectWithTitleExistQuery); if (projectWithSameTitleExists) { throw new ProjectWithSameTitleExistsException(); } _eventStoreRepository.Save(project); }
public bool Handle(DoesProjectWithTitleExistQuery query) { using (var session = _documentStore.OpenSession()) { bool doesProjectExist = session.Query <ProjectTreeNode>().Any(x => x.Title == query.Title); return(doesProjectExist); } }