public IHttpActionResult PostUser(FlightConverter data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { DateTime dt = DateTime.ParseExact(data.DatumPoletanja, "M/dd/yy, h:mm tt", CultureInfo.InvariantCulture); DateTime dt2 = DateTime.ParseExact(data.DatumSletanja, "M/dd/yy, h:mm tt", CultureInfo.InvariantCulture); string input = data.DatumPoletanja; DateTime originalDate = DateTime.Parse(input); bool popust; if (data.Popust == "Da") { popust = true; } else { popust = false; } var flights = new Flight() { BrojPresedanja = data.BrojPresedanja, CenaBiznisKlase = data.CenaBiznisKlase, CenaEkonomskeKlase = data.CenaEkonomskeKlase, CenaPrveKlase = data.CenaPrveKlase, DatumPoletanja = dt, DatumSletanja = dt2, DuzinaPutovanja = data.DuzinaPutovanja, Id = data.Id, IdAvioKompanije = data.IdAvioKompanije, MestoPoletanja = data.MestoPoletanja, MestoSletanja = data.MestoSletanja, OcenaLeta = data.OcenaLeta, VremeTrajanjaLeta = data.VremeTrajanjaLeta, BrojSedista = data.BrojSedista, MestoNaPopustu = data.MestoNaPopustu, ProcenatPopusta = data.ProcenatPopusta, Popust = popust }; //try { objEntity.Flights.Add(flights); objEntity.SaveChanges(); } catch (Exception ex) { throw; } return(Ok(data)); }
private static void ProcessFlights(string csvFilePath) { // Construct the Batch Processor: var processor = new FlightsBatchProcessor(ConnectionString); // Create the Converter: var converter = new FlightConverter(); // Access to the List of Parsers: Parsers // Use the Flights Parser: .FlightStatisticsParser // Read the File: .ReadFromFile(csvFilePath, Encoding.UTF8) // As an Observable: .ToObservable() // Batch in 80000 Entities / or wait 1 Second: .Buffer(TimeSpan.FromSeconds(5), 80000) // And subscribe to the Batch .Subscribe(records => { var validRecords = records // Get the Valid Results: .Where(x => x.IsValid) // And get the populated Entities: .Select(x => x.Result) // Group by WBAN, Date and Time to avoid duplicates for this batch: .GroupBy(x => new { x.UniqueCarrier, x.FlightNumber, x.FlightDate }) // If there are duplicates then make a guess and select the first one: .Select(x => x.First()) // Convert into the Sql Data Model: .Select(x => converter.Convert(x)) // Evaluate: .ToList(); // Finally write them with the Batch Writer: processor.Write(validRecords); }); }
private static void ProcessFlights(DGraphClient client, string csvFilePath) { // Create the Converter: var converter = new FlightConverter(); // Access to the List of Parsers: Parsers // Use the Flights Parser: .FlightStatisticsParser // Read the File: .ReadFromFile(csvFilePath, Encoding.UTF8) // As an Observable: .ToObservable() // Batch Entities by Time / Count: .Buffer(TimeSpan.FromSeconds(1), 1000) // And subscribe to the Batch synchronously (we don't want to handle too much backpressure here): .Subscribe(records => { var validRecords = records // Get the Valid Results: .Where(x => x.IsValid) // And get the populated Entities: .Select(x => x.Result) // Group by WBAN, Date and Time to avoid duplicates for this batch: .GroupBy(x => new { x.UniqueCarrier, x.FlightNumber, x.FlightDate }) // If there are duplicates then make a guess and select the first one: .Select(x => x.First()) // Convert into the DGraph Data Model: .Select(x => converter.Convert(x)) // Evaluate: .ToList(); // Finally write them with the Batch Writer: client.Mutate(validRecords); }); }
public async Task <Flight> GetFromFlight(string travelIdentity) { var flight = await FlightRepository.GetFromFlight(travelIdentity); return(FlightConverter.ToDomainFlight(flight)); }
public async Task AddFromFlight(Flight flight, string travelIdentity) { var dbFlight = FlightConverter.ToDBFlight(flight); await FlightRepository.AddFromFlight(dbFlight, travelIdentity); }
public async Task<Airport[]> GetNearestAirport(float latitude, float longitude) { var response = await FlightsApiClient.GetNearestAirports(latitude, longitude); return FlightConverter.ToDomainAirport(response).ToArray(); }
public async Task<Flight> GetFlightStatus(string flightNumber, string date) { var flightResponse = await FlightsApiClient.GetFlightStatus(flightNumber, date); return FlightConverter.ToDomainFlight(flightResponse); }
public async Task<IEnumerable<Flight>> GetSchedule(string origin, string destination, string date) { var flightResponse = await FlightsApiClient.GetSchedule(origin, destination, date); if (flightResponse == null) return new List<Flight>(); return FlightConverter.ToDomainFlights(flightResponse); }