public async Task <Unit> Handle(DeleteEventGuideCommand request, CancellationToken cancellationToken) { if ((await DataContext.EventGuides.AsNoTracking().FirstOrDefaultAsync(m => m.Id == request.Id, cancellationToken)) == null) { throw new EntityNotFoundException(nameof(EventGuide), request.Id); } var entity = new EventGuide { Id = request.Id, RowVersion = request.RowVersion }; try { DataContext.EventGuides.Remove(entity); await DataContext.SaveChangesAsync(cancellationToken); return(Unit.Value); } catch (DbUpdateConcurrencyException ex) { throw ex; } }
public async Task <Unit> Handle(CreateEventGuideCommand request, CancellationToken cancellationToken) { var entity = new EventGuide { EventId = request.EventId, GuideId = request.Model.GuideId }; await DataContext.EventGuides.AddAsync(entity, cancellationToken); await DataContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }