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 <LiabilityVm> Handle(GetLiabilityQuery request, CancellationToken cancellationToken) { var entity = await GetLiabilityWithVehilcleInfo(request.Id, request.Liability); if (entity == null) { throw new NotFoundException(liabilityUtils.GetLiabilityName(request.Liability), request.Id); } var liability = mapper.Map <GetLiabilityDto>(entity); liability.LiabilityType = (int)request.Liability; return(new LiabilityVm { Liability = liability }); }
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); }