/// <summary> /// Map InitialLocationDTO to InitialLocation Entity /// </summary> /// <param name="flightPlanDTO"></param> /// <returns></returns> private static InitialLocation FactoryInitialLocation(FlightPlanDTO flightPlanDTO) { return(new InitialLocation { Longitude = flightPlanDTO.InitialLocation.Longitude, Latitude = flightPlanDTO.InitialLocation.Latitude, DateTime = DateTimeOffset.Parse(flightPlanDTO.InitialLocation.DateTime).UtcDateTime }); }
/// <summary> /// Map LocationDTO to Location Entity /// </summary> /// <param name="flightPlanDTO"></param> /// <returns></returns> private static IEnumerable <Location> FactoryLocation(FlightPlanDTO flightPlanDTO) { return(from segment in flightPlanDTO.Segments select new Location { Longitude = segment.Longitude, Latitude = segment.Latitude, TimeSpanSeconds = segment.TimeSpanSeconds }); }
public async Task <ActionResult <FlightPlanDTO> > PostFlightPlan(FlightPlanDTO flightPlan) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } var plane = _context.Planes.Single(p => p.RegistrationNo.Equals(flightPlan.Model)); flightPlan.Model = plane.Model; _context.FlightPlans.Add(flightPlan); await _context.SaveChangesAsync(); return(Ok()); }
//public static bool Compare(Flight x, Flight y) //{ // if (x == null && y == null) // return true; // // Not checking the flight plan in the flight // if (x.CompanyName == y.CompanyName && x.DateTime == y.DateTime // && x.FlightPlanId == y.FlightPlanId && x.Id == y.Id // && x.IsExternal == y.IsExternal && x.Latitude == y.Latitude && x.Longitude == y.Longitude // && x.Passengers == y.Passengers && (x.FlightIdentifier == y.FlightIdentifier || (x.FlightIdentifier.Length == 0 && y.FlightIdentifier.Length == 0))) // return true; // return false; //} public static bool Compare(FlightPlanDTO x, FlightPlanDTO y) { if (x == null && y == null) { return(true); } if (x.CompanyName == y.CompanyName && Compare(x.InitialLocation, y.InitialLocation) && x.Passengers == y.Passengers && x.Segments == y.Segments) { return(true); } else { return(false); } }
public async Task <ActionResult> Post(FlightPlanDTO flightPlanDTO) { FlightPlan flightPlan = new FlightPlan { Passengers = flightPlanDTO.Passengers, CompanyName = flightPlanDTO.CompanyName, InitialLocation = FactoryInitialLocation(flightPlanDTO), Segments = (FactoryLocation(flightPlanDTO)).ToList() }; string lastId = !_context.FlightPlans.Include(item => item.Flight) .OrderByDescending( item => item.Flight.FlightIdentifier).Any() ? "AAAA-0000" : _context.FlightPlans.Include(item => item.Flight) .OrderByDescending(item => item.Flight.FlightIdentifier) .First().Flight.FlightIdentifier; Flight flight = FactoryFlight(flightPlan, lastId); await DataBaseCalls.AddAFlightPlanAndAFlight(_context, flightPlan, flight); return(Created("", null)); }
public FlightPlanDTO GetTestFlightPlanVer2() { var flightPlan = new FlightPlanDTO(); flightPlan.CompanyName = "A Cooler Test Company"; flightPlan.InitialLocation = new InitialLocationDTO(); flightPlan.InitialLocation.Latitude = 30; flightPlan.InitialLocation.Longitude = 30; DateTime dateTime = DateTime.UtcNow; flightPlan.InitialLocation.DateTime = dateTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"); flightPlan.Passengers = 55; var mockSegmants = new List <LocationDTO>(); var loc1 = new LocationDTO(); loc1.Latitude = 4; loc1.Longitude = 2; loc1.TimeSpanSeconds = 5000; var loc2 = new LocationDTO(); loc1.Latitude = 7; loc1.Longitude = 9; loc1.TimeSpanSeconds = 40000; mockSegmants.Add(loc1); mockSegmants.Add(loc2); flightPlan.Segments = mockSegmants.ToArray(); return(flightPlan); }
public FlightPlanDTO GetTestFlightPlan() { var flightPlan = new FlightPlanDTO(); flightPlan.CompanyName = "Test Company"; flightPlan.InitialLocation = new InitialLocationDTO(); flightPlan.InitialLocation.Latitude = 12.5; flightPlan.InitialLocation.Longitude = 12.5; DateTime dateTime = DateTime.UtcNow; flightPlan.InitialLocation.DateTime = dateTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"); flightPlan.Passengers = 8; var mockSegmants = new List <LocationDTO>(); var loc1 = new LocationDTO(); loc1.Latitude = 10; loc1.Longitude = 10; loc1.TimeSpanSeconds = 10; mockSegmants.Add(loc1); //flightPlan.EndDateFlight = new System.DateTime(2020, 8, 5, 4, 20, 13); //flightPlan.FinalLocation = loc1; flightPlan.Segments = mockSegmants.ToArray(); return(flightPlan); }