public async Task <Unit> Handle(DeleteTextCommand request, CancellationToken cancellationToken) { var entity = await _context.Text.FindAsync(request.TextId); if (entity == null) { throw new NotFoundException(nameof(Text), request.TextId); } _context.Text.Remove(entity); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(UpdateTextCommand request, CancellationToken cancellationToken) { var entity = await _context.Text.FindAsync(request.TextId); if (entity == null) { throw new NotFoundException(nameof(Text), request.TextId); } entity.TextId = request.TextId; entity.Language = request.Language; entity.Branch = request.Branch; entity.Area = request.Area; entity.Key = request.Key; entity.Value = request.Value; await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Guid> Handle(CreateTextCommand request, CancellationToken cancellationToken) { var entity = new Text { TextId = Guid.NewGuid(), Language = request.Language, Branch = request.Branch, Area = request.Area, Key = request.Key, Value = request.Value, }; _context.Text.Add(entity); await _context.SaveChangesAsync(cancellationToken); await _mediator.Publish(new TextCreated { TextId = entity.TextId }, cancellationToken); return(entity.TextId); }