public async Task <IActionResult> AddFlightAsync([FromBody] FlightNew flight) { if (ModelState.IsValid) { await _flightService.AddFlightAsync(flight); return(Accepted()); } return(BadRequest(ModelState)); }
public async Task <ActionResult <FlightDTO> > Add([FromBody] FlightDTO flightDto) { if (flightDto == null) { return(BadRequest()); } await flightService.AddFlightAsync(flightDto); return(Ok(flightDto)); }
public async Task ProcessFlightsAsync() { var uploadedFiles = flightLogFileService.GetUploadedFlightLogFiles(); foreach (var flightLog in uploadedFiles) //amelyek még nem voltak feldolgozva { string path = flightLog.FilePath; try { // Open the text file using a stream reader. using (StreamReader sr = new StreamReader(path)) { string line; Flight flight = new Flight(); flight.ApplicationUserId = flightLog.ApplicationUserId; //kinek a repülese flight.FlightStatus = FlightStatus.WaitingForAcceptance; while ((line = sr.ReadLine()) != null) { flightService.ParseString(line, flight); } await flightService.SetAirportsAsync(flight); flightLog.FlightLogFileStatus = FlightLogFileStatus.Processed; await flightService.AddFlightAsync(flight); gPSRecordService.SetColor(flight); var optimizedGPSRecords = GetApproximatingNodes(flight.GPSRecords.ToList()); foreach (var gpsRecord in optimizedGPSRecords) { flight.GPSRecords.Single(ent => ent.GPSRecordId == gpsRecord.GPSRecordId).IsOptimized = true;; } await applicationContext.SaveChangesAsync(); } } catch (IOException e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } } }
public async Task <ActionResult <FlightDto> > Post(int accountId, [FromBody] FlightDto newFlight) { try { Guard.AgainstAccountNumberMismatch(GetAccountIdClaim(), accountId.ToString(), "userClaim.accountId", "accountId"); var result = await _flightService.AddFlightAsync(accountId, newFlight); return(Ok(result)); } catch (ArgumentNullException) { return(BadRequest("Error with input flight")); } catch (AccountConflictException) { return(Forbid()); } catch (Exception e) { return(BadRequest($"Error adding flight")); } }
public async Task <ActionResult> PostFlightAsync(SaveFlightDTO saveFlightDTO) { var res = await _service.AddFlightAsync(saveFlightDTO); return(res); }