/// <summary>
 /// Updates the associated checkpoint's flight list with the flight object
 /// </summary>
 /// <param name="newCheckpointSerial">the flight's next checkpoint serial</param>
 /// <param name="checkpointPosition">the current flight's position as a TextBlock name property</param>
 /// <param name="checkpointSerial">the current flight's checkpoint serial</param>
 /// <param name="flight">the associated flight object</param>
 /// <returns>string format for the flight's next checkpoint type</returns>
 public string UpdateCheckpoints(int newCheckpointSerial, string lastCheckpointPosition, int lastCheckpointSerial, FlightDTO flight)
 {
     //if the previous checkpoint's control name's value is the following action
     if (lastCheckpointPosition == "none")
     {
         //updates the flight in DB as a new flight
         UpdateFlightObject(flight, newCheckpointSerial, lastCheckpointSerial, true);
         //returns the first checkpoint's type
         return(CheckpointType.Landing.ToString());
     }
     //if the flight is not new, updates the checkpoint the flight passes between
     CTDB.UpdateCheckpoint(newCheckpointSerial, lastCheckpointSerial, ConvertToEntity(flight));
     //returns the next checkpoint type by the last checkpoint's control name
     if (lastCheckpointPosition == "txtblckFlightArr3")
     {
         return(CheckpointType.RunwayLanded.ToString());
     }
     else if (lastCheckpointPosition == "lstvwParkDepart")
     {
         return(CheckpointType.RunwayDeparting.ToString());
     }
     ////returns the next checkpoint type of the current flight's checkpoint type
     else
     {
         return(CTDB.Flights.FirstOrDefault(f => f.FlightSerial == flight.FlightSerial).Checkpoint.CheckpointType.ToString());
     }
 }
        public CheckpointDTO GetCheckpoint(string checkpointSerial, string checkpointType)
        {
            int serial = default(int);

            int.TryParse(checkpointSerial, out serial);
            return(new CheckpointDTO()
            {
                Duration = CTDB.GetCheckpoint(serial).Duration
            });
        }
 public void InitializeDatabase()
 {
     try
     {
         CTDB.InitializeDatabase();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
     FlightsDTOs.Clear();
 }
        protected override Flight ConvertToEntity(FlightDTO dto)
        {
            Flight flight = new Flight()
            {
                FlightSerial = dto.FlightSerial,
                IsAlive      = dto.IsAlive
            };

            if (dto.Checkpoint != null)
            {
                flight.Checkpoint   = CTDB.GetCheckpoint(dto.Checkpoint.Serial);
                flight.CheckpointId = CTDB.GetCheckpoint(dto.Checkpoint.Serial).CheckpointId;
            }
            return(flight);
        }
        /// <summary>
        /// Create a flight model with default values in DB
        /// </summary>
        /// <param name="flightSerial">the random serial generated by the timing system</param>
        /// <returns>the created flight object</returns>
        public FlightDTO CreateFlightObject(int flightSerial)
        {
            //creates a local process object of type landing
            ProcessDTO process = new ProcessDTO()
            {
                ProcessType = CTDB.GetProcess(ProcessType.LandingProcess.ToString()).ProcessType,
                ProcessId   = CTDB.GetProcess(ProcessType.LandingProcess.ToString()).ProcessId,
                Flights     = new List <FlightDTO>()
            };

            //creates the process's checkpoints
            foreach (Checkpoint cp in CTDB.GetProcess(ProcessType.LandingProcess.ToString()).Checkpoints)
            {
                process.Checkpoints.Add(new CheckpointDTO()
                {
                    CheckpointType = cp.CheckpointType,
                    CheckpointId   = cp.CheckpointId,
                    Process        = process,
                    ProcessId      = cp.ProcessId,
                    Duration       = cp.Duration,
                    Serial         = cp.Serial,
                    Flights        = new List <FlightDTO>()
                });
            }
            //creates the flight in the landing process
            FlightDTO flight = new FlightDTO()
            {
                FlightSerial = flightSerial,
                IsAlive      = false,
                Process      = process,
                ProcessId    = process.ProcessId
            };

            //adds flight to the repo's flight list
            FlightsDTOs.Add(flight);
            //returns the created flight after updated in DB
            return(flight = ConvertToDTO(CTDB.CreateFlight(ConvertToEntity(flight))));
        }
 /// <summary>
 /// Gets a specified flight object by flight serial
 /// </summary>
 /// <param name="flightSerial">the requested serial</param>
 /// <returns>the requested flight object</returns>
 public FlightDTO GetFlightObject(int flightSerial)
 {
     return(ConvertToDTO(CTDB.GetFlight(flightSerial)));
 }
 public bool DisposeFlight(int flightSerial)
 {
     return(CTDB.DisposeFlight(flightSerial));
 }
 /// <summary>
 /// Updates the flight object's checkpoint
 /// </summary>
 /// <param name="flight">the current flight object</param>
 /// <param name="newCheckpointSerial">the next checkpoint's serial</param>
 /// <param name="lastCheckpointSerial">the last checkpoint's serial</param>
 /// <param name="isNew">indicates if the flight is new or not</param>
 public void UpdateFlightObject(FlightDTO flight, int newCheckpointSerial, int lastCheckpointSerial, bool isNew)
 {
     CTDB.UpdateFlight(ConvertToEntity(flight), newCheckpointSerial, lastCheckpointSerial, isNew);
 }