コード例 #1
0
        public void RandomlyAssignPlanesToFlights()
        {
            var planes = _planeRepository.GetPlanes();

            foreach (var plane in planes)
            {
                var days = _flights.Select(f => f.Day).Distinct();
                foreach (var day in days)
                {
                    var flight = _flights.FirstOrDefault(f => f.Day == day && f.AssignedPlane == null);
                    if (flight != default)
                    {
                        flight.AssignedPlane = plane;
                    }
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                // Mimicking Dependency Injection
                PseudoDIStartUp();

                var loopActive    = true;
                var invalidChoice = false;

                // Interactive menu
                do
                {
                    #region UI Decoration
                    var bufferWidth = Console.BufferWidth;
                    Console.Clear();
                    Console.WriteLine(new String('=', bufferWidth));
                    for (var iLine = 1; iLine < 7; iLine++)
                    {
                        Console.WriteLine($"|{new String(' ', bufferWidth - 2)}|");
                    }

                    Console.SetCursorPosition(2, 2);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("COMPANY:");
                    Console.SetCursorPosition(15, 2);
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.Write("TRANSPORT.LY");
                    Console.SetCursorPosition(2, 4);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("INVENTORY:");
                    Console.SetCursorPosition(3, 5);
                    Console.Write("- PLANES:");
                    Console.SetCursorPosition(15, 5);
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.Write(PlaneRepository.GetPlanes().Count);

                    Console.ForegroundColor = ConsoleColor.Yellow;
                    var dateString = DateTime.Now.ToLongDateString();
                    var timeString = DateTime.Now.ToLongTimeString();
                    Console.SetCursorPosition(bufferWidth - (dateString.Length + timeString.Length + 5), 2);
                    Console.Write(dateString);
                    Console.SetCursorPosition(bufferWidth - (timeString.Length + 2), 2);
                    Console.Write(timeString);

                    Console.ResetColor();
                    Console.SetCursorPosition(0, 7);
                    Console.WriteLine(new String('=', bufferWidth));
                    #endregion

                    if (invalidChoice)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.SetCursorPosition(0, 8);
                        Console.Write("Invalid  choice. Please try again");
                        Console.ResetColor();
                    }

                    Console.SetCursorPosition(0, 9);
                    Console.Write("Please type the number, 0 for flight Table, 1 or 2 are for user story # or type Q to Exit? ");
                    var choice = Console.ReadKey();
                    invalidChoice = false;
                    switch (choice.Key)
                    {
                    case ConsoleKey.D0:
                    case ConsoleKey.NumPad0:
                        ShowFlightTable();
                        break;

                    case ConsoleKey.D1:
                    case ConsoleKey.NumPad1:
                        RunUserStoryOne();
                        break;

                    case ConsoleKey.D2:
                    case ConsoleKey.NumPad2:
                        RunUserStoryTwo();
                        break;

                    case ConsoleKey.Q:
                        loopActive = false;
                        break;

                    default:
                        invalidChoice = true;
                        break;
                    }
                } while (loopActive);

                Console.Clear();
                Console.SetCursorPosition(Console.BufferWidth / 2 - 15, Console.WindowHeight / 2);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Thank You and Have a nice day.");
                Console.ResetColor();
                Console.SetCursorPosition(0, Console.WindowHeight - 5);
            }
            catch (Exception ex)
            {
                // Global hanlder in case we have errors
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"Error ({ex.GetType().ToString()}): {ex.Message}");
                Console.ResetColor();
            }
        }