/// <summary>
 /// Removes an airline object from list
 /// </summary>
 /// <param name="airlineObject">Airline object you need to remove</param>
 /// <returns>Positive if removed</returns>
 public virtual bool Delete(AirlineObject airlineObject)
 {
     try
     {
         AirlineObjects = AirlineObjects.Where(arg => arg != null && arg.ID != airlineObject.ID).ToList();
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
示例#2
0
 /// <summary>
 /// Removes an airline object from list
 /// </summary>
 /// <param name="airlineObject">Airline object you need to remove</param>
 /// <returns>Positive if removed</returns>
 public virtual bool Delete(AirlineObject airlineObject)
 {
     try
     {
         var prevCount         = AirlineObjects.Count();
         var tmpAirlineObjects = AirlineObjects.Where(arg => arg != null && arg.ID != airlineObject.ID).ToArray();
         Array.Resize(ref tmpAirlineObjects, prevCount);
         AirlineObjects = tmpAirlineObjects;
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
示例#3
0
        public override void ProcessOptions(string[] values)
        {
            var id = 0;

            switch (_selectedOption)
            {
            case AirlineOptions.ShowPassangers:
                CurrentAirlineObjects = AirlineObjects.Where(arg => (arg as Passenger) != null).ToArray();
                Options = new AirlineOptions[s_general.Length + s_edit.Length];
                s_edit.CopyTo(Options, 0);
                s_general.CopyTo(Options, s_edit.Length);
                break;

            case AirlineOptions.SearchPassangers:
                if (values.Length > 0)
                {
                    Find(values);
                }
                else
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true
                    });
                }
                Options = new AirlineOptions[s_general.Length + s_edit.Length];
                s_edit.CopyTo(Options, 0);
                s_general.CopyTo(Options, s_edit.Length);
                break;

            case AirlineOptions.AddAPassanger:
                if (values.Length > 0)
                {
                    if (Add(values, new Passenger(), null))
                    {
                        OnDisplayInfoChanged(new AirlineObjectEventArgs {
                            DisplayInfo = "The Passanger has been added successfully", ConsoleColor = ConsoleColor.Green
                        });
                    }
                    else
                    {
                        OnDisplayInfoChanged(new AirlineObjectEventArgs {
                            DisplayInfo = "The Passanger wasn't added", ConsoleColor = ConsoleColor.Red, HasError = true
                        });
                    }
                }
                else
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true
                    });
                }
                CurrentAirlineObjects = AirlineObjects.ToArray();
                Options = new AirlineOptions[s_general.Length + s_edit.Length];
                s_edit.CopyTo(Options, 0);
                s_general.CopyTo(Options, s_edit.Length);
                break;

            case AirlineOptions.EditThePassanger:
                if (values.Length > 0)
                {
                    if (Edit(values))
                    {
                        OnDisplayInfoChanged(new AirlineObjectEventArgs {
                            DisplayInfo = "The Passanger has been edited successfully", ConsoleColor = ConsoleColor.Green
                        });
                    }
                }
                else
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true
                    });
                }
                CurrentAirlineObjects = AirlineObjects.ToArray();
                Options = new AirlineOptions[s_general.Length + s_edit.Length];
                s_edit.CopyTo(Options, 0);
                s_general.CopyTo(Options, s_edit.Length);
                break;

            case AirlineOptions.DeleteThePassanger:
                if (values.Length > 0)
                {
                    var optionsArray = values[0].Split(' ');
                    if ((optionsArray.Length == 3) && (int.TryParse(optionsArray[2], out id)) && (id > 0) && (id < CurrentAirlineObjects.Length + 1))
                    {
                        if (Delete(CurrentAirlineObjects[id - 1]))
                        {
                            CurrentAirlineObjects = AirlineObjects.ToArray();
                            OnDisplayInfoChanged(new AirlineObjectEventArgs {
                                DisplayInfo = "Removed Successfully"
                            });
                        }
                    }
                }
                else
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true
                    });
                }
                Options = new AirlineOptions[s_general.Length + s_edit.Length];
                s_edit.CopyTo(Options, 0);
                s_general.CopyTo(Options, s_edit.Length);
                break;

            case AirlineOptions.ClearTheConsole:
                OnDisplayInfoChanged(new AirlineObjectEventArgs {
                    ClearConsole = true
                });
                CurrentAirlineObjects = null;
                Options = s_general;
                break;

            case AirlineOptions.Info:
                OnDisplayInfoChanged(new AirlineObjectEventArgs
                {
                    ConsoleColor = ConsoleColor.Yellow,
                    DisplayInfo  = "You are inside flight where you can work with passangers and it's info, \n" +
                                   "In case if you need to go back to Airline manager, just chose 'Exit or level up' menu item"
                });
                CurrentAirlineObjects = null;
                Options = s_general;
                break;

            case AirlineOptions.ExitOrLevelUp:
                CurrentAirlineManager = null;
                CurrentAirlineObjects = null;
                Options = s_general;
                Reset();
                break;
            }
        }
示例#4
0
        public override void ProcessOptions(string[] values)
        {
            var id = 0;

            switch (_selectedOption)
            {
            case AirlineOptions.ShowAllFlights:
                CurrentAirlineObjects = AirlineObjects.Where(arg => (arg as Flight) != null).ToList();
                if (CurrentAirlineObjects.Count > 0)
                {
                    Options.Clear();
                    Options.AddRange(s_edit);
                    Options.AddRange(s_general.Where(arg => Options.IndexOf(arg) < 0));
                }
                break;

            case AirlineOptions.ShowArrivals:
                CurrentAirlineObjects = AirlineObjects.Where(arg => (arg as Flight) != null && ((Flight)arg).Type == FlightType.Arrival).ToList();
                if (CurrentAirlineObjects.Count > 0)
                {
                    Options.Clear();
                    Options.AddRange(s_edit);
                    Options.AddRange(s_general.Where(arg => Options.IndexOf(arg) < 0));
                }
                break;

            case AirlineOptions.ShowDepartues:
                CurrentAirlineObjects = AirlineObjects.Where(arg => (arg as Flight) != null && ((Flight)arg).Type == FlightType.Departure).ToList();
                if (CurrentAirlineObjects.Count > 0)
                {
                    Options.Clear();
                    Options.AddRange(s_edit);
                    Options.AddRange(s_general.Where(arg => Options.IndexOf(arg) < 0));
                }
                break;

            case AirlineOptions.SearchFlights:
                if (values.Length > 0)
                {
                    Find(values);
                }
                else
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true
                    });
                }
                Options.Clear();
                Options.AddRange(s_edit);
                Options.AddRange(s_general.Where(arg => Options.IndexOf(arg) < 0));
                break;

            case AirlineOptions.AddAFlight:
                if (values.Length > 0)
                {
                    if (Add(values))
                    {
                        OnDisplayInfoChanged(new AirlineObjectEventArgs {
                            DisplayInfo = "The Flight has been added successfully", ConsoleColor = ConsoleColor.Green
                        });
                    }
                    else
                    {
                        OnDisplayInfoChanged(new AirlineObjectEventArgs {
                            DisplayInfo = "The Flight wasn't added", ConsoleColor = ConsoleColor.Red, HasError = true
                        });
                    }
                }
                else
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true
                    });
                }
                CurrentAirlineObjects = AirlineObjects;
                Options.Clear();
                Options.AddRange(s_edit);
                Options.AddRange(s_general.Where(arg => Options.IndexOf(arg) < 0));
                break;

            case AirlineOptions.EditTheFlight:
                if (values.Length > 0)
                {
                    if (Edit(values))
                    {
                        OnDisplayInfoChanged(new AirlineObjectEventArgs {
                            DisplayInfo = "The Flight has been edited successfully", ConsoleColor = ConsoleColor.Green
                        });
                    }
                }
                else
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true
                    });
                }
                CurrentAirlineObjects = AirlineObjects;
                Options.Clear();
                Options.AddRange(s_edit);
                Options.AddRange(s_general.Where(arg => Options.IndexOf(arg) < 0));
                break;

            case AirlineOptions.EditPassangersOfTheFlight:
                if (values.Length > 0)
                {
                    var optionsArray = values[0].Split(' ');
                    if ((optionsArray.Length == 3) && (int.TryParse(optionsArray[2], out id)) && (id > 0) && (id < CurrentAirlineObjects.Count + 1))
                    {
                        var flight = CurrentAirlineObjects[id - 1] as Flight;
                        if (flight != null)
                        {
                            IndexOfCurrentAirlineManager = id - 1;
                            CurrentAirlineManager        = flight;
                        }
                    }
                }
                CurrentAirlineObjects = null;
                Options = new List <AirlineOptions>();
                Options.AddRange(s_general);
                break;

            case AirlineOptions.DeleteTheFlight:
                if (values.Length > 0)
                {
                    var optionsArray = values[0].Split(' ');
                    if ((optionsArray.Length == 3) && (int.TryParse(optionsArray[2], out id)) && (id > 0) && (id < CurrentAirlineObjects.Count + 1))
                    {
                        if (Delete(CurrentAirlineObjects[id - 1]))
                        {
                            CurrentAirlineObjects = AirlineObjects;
                            OnDisplayInfoChanged(new AirlineObjectEventArgs {
                                DisplayInfo = "Removed Successfully"
                            });
                        }
                    }
                }
                else
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true
                    });
                }
                Options.Clear();
                Options.AddRange(s_edit);
                Options.AddRange(s_general.Where(arg => Options.IndexOf(arg) < 0));
                break;

            case AirlineOptions.ClearTheConsole:
                OnDisplayInfoChanged(new AirlineObjectEventArgs {
                    ClearConsole = true
                });
                CurrentAirlineObjects = null;
                Options = new List <AirlineOptions>();
                Options.AddRange(s_general);
                break;

            case AirlineOptions.Info:
                OnDisplayInfoChanged(new AirlineObjectEventArgs
                {
                    ConsoleColor = ConsoleColor.Yellow,
                    DisplayInfo  = "You are inside Airport manager where you can work with flights and it's info, " +
                                   "if you would like to receive an information about passanger and edit it, please go to 'Edit passangers of the flight'.\n" +
                                   "In case if you need to exit from Application, just chose 'Exit or level up' menu item"
                });
                CurrentAirlineObjects = null;
                Options = new List <AirlineOptions>();
                Options.AddRange(s_general);
                break;

            case AirlineOptions.LoadFromFile:
                if (values.Length > 0)
                {
                    try
                    {
                        if (OpenFromFile(values[0]))
                        {
                            OnDisplayInfoChanged(new AirlineObjectEventArgs {
                                DisplayInfo = "Loaded successfully", ConsoleColor = ConsoleColor.Green
                            });
                            CurrentAirlineObjects = AirlineObjects;
                        }
                        else
                        {
                            OnDisplayInfoChanged(new AirlineObjectEventArgs {
                                DisplayInfo = "Can't load from file", ConsoleColor = ConsoleColor.Red, HasError = true
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        OnDisplayInfoChanged(new AirlineObjectEventArgs {
                            DisplayInfo = $"Couldn't load data from file because of: {ex.Message}", ConsoleColor = ConsoleColor.Red, HasError = true
                        });
                    }
                }
                else
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true
                    });
                }
                break;

            case AirlineOptions.SaveToFile:
                if (values.Length > 0)
                {
                    try
                    {
                        if (SaveToFile(values[0]))
                        {
                            OnDisplayInfoChanged(new AirlineObjectEventArgs {
                                DisplayInfo = "Saved successfully", ConsoleColor = ConsoleColor.Green
                            });
                        }
                        else
                        {
                            OnDisplayInfoChanged(new AirlineObjectEventArgs {
                                DisplayInfo = "Can't save to file", ConsoleColor = ConsoleColor.Red, HasError = true
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        OnDisplayInfoChanged(new AirlineObjectEventArgs {
                            DisplayInfo = $"Couldn't save data to file because of: {ex.Message}", ConsoleColor = ConsoleColor.Red, HasError = true
                        });
                    }
                }
                else
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true
                    });
                }
                break;

            case AirlineOptions.ExitOrLevelUp:
                CurrentAirlineManager = null;
                CurrentAirlineObjects = null;
                Options = new List <AirlineOptions>();
                Options.AddRange(s_general);
                Reset();
                break;
            }
        }