public void AddNewLapTime(AddNewLapTimeRequest request) { var track = _context.Tory.Any(t => t.IdTor == request.IdTor); if (!track) { throw new NoTrackException($"Track with id = {request.IdTor} does not exist!"); } var gokart = _context.Gokarty.Any(g => g.IdGokart == request.IdGokart); if (!gokart) { throw new NoGokartException($"Gokart with id = {request.IdGokart} does not exist!"); } var driver = _context.Kierowcy.Any(k => k.IdKierowca == request.IdKierowca); if (!driver) { throw new NoDriverException($"Driver with id = {request.IdKierowca} does not exist!"); } if (request.DataPrzejazdu.CompareTo(DateTime.Now) > 0) { throw new DateIsLaterThanNowException($"Date {request.DataPrzejazdu} is later than current date!"); } var newLap = new Przejazd { Czas = TimeSpan.Parse(request.Czas), DataPrzejazdu = request.DataPrzejazdu, IdTor = request.IdTor, IdGokart = request.IdGokart, IdKierowca = request.IdKierowca }; /* * Przykładowy request z Postmana * * "Czas": "00:04:00.089", * "DataPrzejazdu":"2019-06-17T14:37:39.000", * "IdTor": 3, * "IdGokart": 3, * "IdKierowca": 1 */ _context.Przejazdy.Add(newLap); _context.SaveChanges(); }
public IActionResult AddNewLapTime(AddNewLapTimeRequest request) { try { _service.AddNewLapTime(request); return(Ok()); } catch (NoTrackException exc) { return(NotFound(exc.Message)); } catch (NoDriverException exc) { return(NotFound(exc.Message)); } catch (NoGokartException exc) { return(NotFound(exc.Message)); } catch (DateIsLaterThanNowException exc) { return(BadRequest(exc.Message)); } }