public ActionResult <Infraction> GetInfraction(string id) { var infraction = infractionService.GetInfraction(id); if (infraction == null) { return(NotFound()); } return(infraction); }
public ActionResult <Vehicle> RegisterVehicleInfraction(string vehicleId, string infractionId, InfractionViewModel request) { var vehicle = vehicleService.GetVehicle(vehicleId); if (vehicle == null) { return(NotFound("vehicle not found")); } var infraction = infractionService.GetInfraction(infractionId); if (infraction == null) { return(NotFound("infraction not found")); } // in case that the driver is not specified in the request, we assume that the infraction shall be assigned to the main regular driver from this vehicle var driverId = request.DriverId; if (string.IsNullOrEmpty(driverId)) { driverId = vehicle.MainRegularDriverId; } VehicleInfraction vehicleInfraction = new VehicleInfraction { Infraction = infraction, InfractionId = infraction.Id, Vehicle = vehicle, VehicleId = vehicle.Id, InfractionDate = request.InfractionDate, DriverId = driverId, }; var remainingDriverPoints = vehicleInfractionService.RegisterInfraction(vehicleInfraction); return(Ok("Remaining driver points: " + remainingDriverPoints)); }
public int RegisterInfraction(VehicleInfraction vehicleInfraction) { // first register a new infraction linked to the vehicle vehicleInfractionRepository.Add(vehicleInfraction); SaveVehicle(); // second, retrieve the infraction to know the penalty points var infraction = infractionService.GetInfraction(vehicleInfraction.InfractionId); // and finally update the driver points var driver = driverService.GetDriver(vehicleInfraction.DriverId); if (driver.Points > infraction.PointsToDiscount) { driver.Points -= infraction.PointsToDiscount; } else { driver.Points = 0; } driverService.UpdateDriver(driver); return(driver.Points); }
public async Task <IActionResult> Get() { var infractions = await _infractionService.GetInfraction(); return(Ok(infractions)); }