public async Task Rename(ConceptAttribute conceptAttribute, string newName, CancellationToken cancellationToken) { var existing = await _conceptAttributeRepository.GetByConceptAndName(conceptAttribute.ConceptId, newName, cancellationToken); if (existing != null && existing.ConceptAttributeId != conceptAttribute.ConceptAttributeId) { throw new DomainValidationException($"A concept named {newName} already exists."); } conceptAttribute.Rename(newName); }
public async Task Add(ConceptAttribute conceptAttribute, CancellationToken cancellationToken) { var existing = _conceptAttributeRepository.GetByConceptAndName(conceptAttribute.ConceptId, conceptAttribute.Name, cancellationToken); if (existing != null) { throw new DomainValidationException($"A concept attribute named {conceptAttribute.Name} already exists on that concept."); } await _conceptAttributeRepository.Create(conceptAttribute, cancellationToken); }
public async Task Create(ConceptAttribute conceptAttribute, CancellationToken cancellationToken = default(CancellationToken)) { var context = await _ddpContextProvider.Get(); var conceptAttributeTable = new ConceptAttributeTable { ConceptAttributeId = conceptAttribute.ConceptAttributeId, ConceptId = conceptAttribute.ConceptId, Name = conceptAttribute.Name, }; await context.ConceptAttributeTables.AddAsync(conceptAttributeTable, cancellationToken); await _eventStore.StoreEventsFor(conceptAttribute, conceptAttribute.ConceptId, cancellationToken); await _domainEventDispatcher.QueueEvents(conceptAttribute.GetMutatingEvents()); }
public async Task <ConceptAttribute> GetByConceptAndName(Guid conceptId, string name, CancellationToken cancellationToken = default(CancellationToken)) { var context = await _ddpContextProvider.Get(); var conceptAttributeTable = await context.ConceptAttributeTables.SingleOrDefaultAsync(c => c.ConceptId == conceptId && c.Name == name, cancellationToken); if (conceptAttributeTable == null) { return(null); } var stream = await _eventStore.GetEventStreamFor <ConceptAttribute>(conceptAttributeTable.ConceptId, cancellationToken : cancellationToken); var concept = new ConceptAttribute(stream.DomainEvents, stream.StreamVersion); return(concept); }
public async Task <ConceptAttribute> Get(Guid conceptAttributeId, CancellationToken cancellationToken = default(CancellationToken)) { var context = await _ddpContextProvider.Get(); var conceptAttributeTable = await context.ConceptAttributeTables.FindAsync(conceptAttributeId); if (conceptAttributeTable == null) { return(null); } var stream = await _eventStore.GetEventStreamFor <ConceptAttribute>(conceptAttributeId, cancellationToken : cancellationToken); var concept = new ConceptAttribute(stream.DomainEvents, stream.StreamVersion); return(concept); }
public async Task Update(ConceptAttribute conceptAttribute, CancellationToken cancellationToken = default(CancellationToken)) { var context = await _ddpContextProvider.Get(); var existing = await context.FindAsync <ConceptAttributeTable>(conceptAttribute.ConceptAttributeId); if (existing == null) { throw new EntityNotFoundException("nope doesn't exist"); } existing.ConceptId = conceptAttribute.ConceptId; existing.Name = conceptAttribute.Name; await context.SaveChangesAsync(cancellationToken); await _eventStore.StoreEventsFor(conceptAttribute, conceptAttribute.ConceptId, cancellationToken); await _domainEventDispatcher.QueueEvents(conceptAttribute.GetMutatingEvents()); }