public async Task <ActionResult <FlightLeg> > PostFlightLeg(FlightLeg flightLeg) { _context.FlightLeg.Add(flightLeg); await _context.SaveChangesAsync(); return(CreatedAtAction("GetFlightLeg", new { id = flightLeg.LegNum }, flightLeg)); }
public async Task <IActionResult> PutFlightLeg(int id, FlightLeg flightLeg) { if (id != flightLeg.LegNum) { return(BadRequest()); } _context.Entry(flightLeg).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FlightLegExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public FlightLeg UpdateFlightLeg(int id, FlightLeg flightLeg) { if (id <= 0) { throw new ArgumentOutOfRangeException(ErrorMessages.INVALID_ID); } if (flightLeg == null) { throw new ArgumentNullException(ErrorMessages.ENTITY_CANNOT_BE_NULL); } var flightLegToUpdate = this.flightLegs.GetById(id); if (flightLegToUpdate != null) { flightLegToUpdate.DepartureAirportId = flightLeg.DepartureAirportId; flightLegToUpdate.ScheduledDepartureDateTime = flightLeg.ScheduledDepartureDateTime; flightLegToUpdate.ArrivalAirportId = flightLeg.ArrivalAirportId; flightLegToUpdate.ScheduledArrivalDateTime = flightLeg.ScheduledArrivalDateTime; flightLegToUpdate.IsDeleted = flightLeg.IsDeleted; flightLegToUpdate.FlightId = flightLeg.FlightId; flightLegToUpdate.RouteId = flightLeg.RouteId; this.flightLegs.SaveChanges(); } return(flightLegToUpdate); }
public int AddFlightLeg(FlightLeg flightLeg) { if (flightLeg == null) { throw new ArgumentNullException(ErrorMessages.ENTITY_CANNOT_BE_NULL); } this.flightLegs.Add(flightLeg); this.flightLegs.SaveChanges(); return(flightLeg.Id); }
private void View_OnFlightLegsAddItem(object sender, FlightLegsManagementEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(FlightLegsManagementEventArgs)); } var newFlightLeg = new FlightLeg() { DepartureAirportId = e.DepartureAirportId, ScheduledDepartureDateTime = e.ScheduledDepartureDateTime, ArrivalAirportId = e.ArrivalAirportId, ScheduledArrivalDateTime = e.ScheduledArrivalDateTime, FlightId = e.FlightId, RouteId = e.RouteId }; e.Id = this.flightLegsServices.AddFlightLeg(newFlightLeg); }
private void ProcessBucket(IGrouping <DateTime, VW_OperationsMaster> monthBucket) { Log(string.Format("\t--Bucket: {0} items", monthBucket.Key)); using (var infrastructureDb = new InfrastructureDbContext()) { infrastructureDb.Configuration.LazyLoadingEnabled = false; infrastructureDb.Configuration.ProxyCreationEnabled = false; var existingFlightLegsOfMonthBucketQuery = from item in infrastructureDb.Set <FlightLeg>() where item.ScheduledDepartureDateTime.DateTimeUtc.Value.Year == monthBucket.Key.Year && item.ScheduledDepartureDateTime.DateTimeUtc.Value.Month == monthBucket.Key.Month select item; var existingFlightLegsOfMonthBucketGrouped = from fl in existingFlightLegsOfMonthBucketQuery.ToList() group fl by string.Format("{0},{1},{2},{3}", fl.FlightNumberId, fl.AircraftRegisterId, fl.RepetitionReasonCode, fl.ScheduledDepartureDateTime.DateTimeUtc) into flGroup select flGroup; var existingFlightLegsOfMonthBucket = existingFlightLegsOfMonthBucketGrouped .Select(i => i.First()) .ToDictionary( fl => string.Format("{0},{1},{2},{3}", fl.FlightNumberId, fl.AircraftRegisterId, fl.RepetitionReasonCode, fl.ScheduledDepartureDateTime.DateTimeUtc)); Log(string.Format("\tLocal: {0} items", existingFlightLegsOfMonthBucket.Count)); long updateCount = 0; long insertCount = 0; foreach (var sourceEntity in monthBucket) { var flightNumber = flightNumbers.GetValueOrDefault(sourceEntity.FLT_FlightNumber.FlightNumber_AbvNumber, null); var flightNumberId = flightNumber != null ? (Guid?)flightNumber.Id : null; var aircraftRegister = aircraftRegisters.GetValueOrDefault( sourceEntity.GI_AircraftRegister.Code, null); var aircraftRegisterId = aircraftRegister != null ? (Guid?)aircraftRegister.Id : null; var repetitionReasonCode = sourceEntity.LegNumber; var scheduledDepartureDateTime = sourceEntity.Scheduled_DepartureDatetime_UTC; var searchingKey = string.Format("{0},{1},{2},{3}", flightNumberId, aircraftRegisterId, repetitionReasonCode, scheduledDepartureDateTime); var targetEntity = existingFlightLegsOfMonthBucket.GetValueOrDefault(searchingKey, null); if (targetEntity == null) { targetEntity = new FlightLeg(); ((IXafEntityObject)targetEntity).OnCreated(); infrastructureDb.Set <FlightLeg>().Add(targetEntity); existingFlightLegsOfMonthBucket[searchingKey] = targetEntity; insertCount++; } else { updateCount++; } var flightType = FlightType.All.FirstOrDefault(f => f.Code == sourceEntity.FLT_FlightType.Code); targetEntity.FlightTypeId = flightType != null ? (Guid?)flightType.Id : null; targetEntity.FlightNumberId = flightNumberId; targetEntity.AircraftRegisterId = aircraftRegisterId; targetEntity.Status = sourceEntity.Status; targetEntity.ScheduledDepartureDateTime = new TralusDateTime() { DateTimeUtc = sourceEntity.Scheduled_DepartureDatetime_UTC }; targetEntity.EstimatedDepartureDateTime = new TralusDateTime(); targetEntity.ActualDepartureDateTime = new TralusDateTime() { DateTimeUtc = sourceEntity.ACTUAL_DepartureDATETIME_UTC }; targetEntity.EstimatedArrivalDateTime = new TralusDateTime(); targetEntity.ActualArrivalDateTime = new TralusDateTime() { DateTimeUtc = sourceEntity.Arrival_ACTUAL_DATETIME_UTC }; targetEntity.TakeOffDateTime = new TralusDateTime() { DateTimeUtc = sourceEntity.Takeoff_Datetime }; var leg = legs.GetValueOrDefault(sourceEntity.FLT_Route_FlightLeg.Name, null); targetEntity.LegId = leg != null ? (Guid?)leg.Id : null; var arrivlaAirport = airports.GetValueOrDefault( sourceEntity.GI_Airport_ARRIVAL.IATA_AirportCode, null); targetEntity.ArrivalAirportId = arrivlaAirport != null ? (Guid?)arrivlaAirport.Id : null; var departureAirport = airports.GetValueOrDefault(sourceEntity.GI_Airport_DEPARTURE.IATA_AirportCode, null); targetEntity.DepartureAirportId = departureAirport != null ? (Guid?)departureAirport.Id : null; var aircraftType = aircraftTypes.GetValueOrDefault(sourceEntity.GI_AircraftType.IATACode, null); targetEntity.ScheduledAircraftTypeId = aircraftType != null ? (Guid?)aircraftType.Id : null; targetEntity.RepetitionReasonCode = sourceEntity.LegNumber; } Log(string.Format("\tUpdates/Insert: {0}/{1}", updateCount, insertCount)); var sw = Stopwatch.StartNew(); infrastructureDb.SaveChanges(); Log(string.Format("\tSave time: {0} ms", sw.ElapsedMilliseconds)); sw.Stop(); } }