public void ReportDefect(RequestBrokenModel rentModel) { var findMeAsClient = _context.Clients .Where(el => el.FirstName == rentModel.FirstName && el.LastName == rentModel.LastName) .Include(el => el.Rentals) .FirstOrDefault(); if (findMeAsClient == null || findMeAsClient.Rentals == null) { return; } var lastRentedScooterForUser = findMeAsClient.Rentals.OrderByDescending(el => el.EndRentTime).FirstOrDefault(); if (lastRentedScooterForUser != null && (lastRentedScooterForUser.EndRentTime != DateTime.MaxValue && lastRentedScooterForUser.EndRentTime.AddMinutes(15) < DateTime.UtcNow)) { return; } var scooter = _context.Scooters .Include(p => p.Defect) .FirstOrDefault(x => x.Id == lastRentedScooterForUser.ScooterId); if (scooter != null && scooter.Defect == null) { scooter.Defect = new Defect() { DefectType = Defects.Broke, Description = rentModel.AboutBroke }; } else { if (scooter != null) { scooter.Defect.Description = rentModel.AboutBroke; } } _context.SaveChanges(); }
public ActionResult ReportDefect([FromBody] RequestBrokenModel rentModel) { _clientService.ReportDefect(rentModel); return(Ok()); }