public async Task <Unit> Handle(DeleteLiabilityCommand request, CancellationToken cancellationToken) { var entity = await liabilityUtils.FindLiabilityAsync(request.Id, request.Liability, context); if (entity == null) { throw new NotFoundException(liabilityUtils.GetLiabilityName(request.Liability), request.Id); } RemoveFromContext(entity, request.Liability); await context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(UpdateLiabilityCommand request, CancellationToken cancellationToken) { var entity = await liabilityUtils.FindLiabilityAsync(request.Id, request.Liability, context); if (entity == null) { throw new NotFoundException(liabilityUtils.GetLiabilityName(request.Liability), request.Id); } var vehicle = await context.Vehicles.FindAsync(request.VehicleId); if (vehicle == null) { throw new NotFoundException(nameof(Vehicle), request.VehicleId); } entity.Vehicle = vehicle; entity.StartDate = request.StartDate; entity.EndDate = request.EndDate; await context.SaveChangesAsync(cancellationToken); return(Unit.Value); }