Esempio n. 1
0
        private static MobilePhoneStore GetMobilePhoneStoreFromInput(MobilePhoneShop mobilePhoneShop)
        {
            MobilePhoneStore[] mobilePhoneStores = mobilePhoneShop.MobilePhoneStores;
            MobilePhoneStore   mobilePhoneStore  = null;

            do
            {
                Console.WriteLine($"Please write index number of mobilePhoneStore from list below. MobilePhoneStores:");
                PrintStores(mobilePhoneShop, false, false);

                bool isInputInt      = int.TryParse(Console.ReadLine(), out int mobilePhoneStoreIndexFromInput);
                bool isValidInputInt =
                    isInputInt &&
                    mobilePhoneStoreIndexFromInput >= 0 &&
                    mobilePhoneStoreIndexFromInput < mobilePhoneStores.Length &&
                    mobilePhoneStores[mobilePhoneStoreIndexFromInput] != null;

                if (isValidInputInt)
                {
                    mobilePhoneStore = mobilePhoneStores[mobilePhoneStoreIndexFromInput];
                }
                else
                {
                    Console.WriteLine($"=> Invalid number");
                }
            } while (mobilePhoneStore == null);
            return(mobilePhoneStore);
        }
Esempio n. 2
0
        private static string AddStoreToShop(MobilePhoneShop iphoneShop)
        {
            MobilePhoneStore mobilePhoneStore = CreateMobilePhoneStoreFromInput();

            iphoneShop.AddStore(mobilePhoneStore);
            return($"=> Shop '{mobilePhoneStore.GetDescription()}' successfully created.");
        }
Esempio n. 3
0
        private static string PrintStores(MobilePhoneShop iphoneShop,
                                          bool isShowPhonesInsideStore,
                                          bool isShowEmptyStores)
        {
            int currentMobilePhoneStoreIndex = 0;

            if (iphoneShop.MobilePhoneStores.Length == 0)
            {
                Console.WriteLine("=> Please Create some stores - iphoneShop.MobilePhoneStores.Length == 0");
            }
            else
            {
                Console.WriteLine($"=> Shop '{iphoneShop.GetDescription()}' has stores:");
                foreach (var mobilePhoneStore in iphoneShop.MobilePhoneStores)
                {
                    bool isMobilePhoneStoreEmpty = mobilePhoneStore == null;
                    if (!isShowEmptyStores && isMobilePhoneStoreEmpty)
                    {
                        continue;
                    }
                    string stringToShow = $"[{currentMobilePhoneStoreIndex}] - Store cell is ";
                    stringToShow += isMobilePhoneStoreEmpty ? "empty" : $"'{mobilePhoneStore.GetDescription()}'";
                    Console.WriteLine(stringToShow);
                    if (isShowPhonesInsideStore && !isMobilePhoneStoreEmpty)
                    {
                        PrintAllPhonesInStore(mobilePhoneStore);
                    }
                    currentMobilePhoneStoreIndex++;
                }
            }
            return($"=> Stores of a Shop '{iphoneShop}' are printed");
        }
Esempio n. 4
0
 private static bool IsAnyMobilePhoneStoreAvailable(MobilePhoneShop iphoneShop)
 {
     foreach (var mobilePhoneStores in iphoneShop.MobilePhoneStores)
     {
         if (mobilePhoneStores != null)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 5
0
        private static string AddPhoneToStore(MobilePhoneShop iphoneShop)
        {
            if (!IsAnyMobilePhoneStoreAvailable(iphoneShop))
            {
                return($"=> in {iphoneShop.GetDescription()} no real stores are available. Please add any real store before add a phone.");
            }
            MobilePhoneStore store               = GetMobilePhoneStoreFromInput(iphoneShop);
            MobilePhone      mobilePhone         = CreatePhoneFromInput();
            bool             isPhoneAddedToStore = iphoneShop.AddPhoneToStore(mobilePhone, store.Address);
            string           resultMessage       = isPhoneAddedToStore ? "successfully added" : "was not added";

            return($"=> Phone with {mobilePhone.GetDescription()} {resultMessage} to store '{store.GetDescription()}'.");
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            string[] commands = new string[] {
                "quit",
                "add store to shop",
                "add phone to store",
                "show all phones in stores",
                "clear console"
            };
            MobilePhoneShop iphoneShop = CreateMobileShopFromInput();
            string          command    = string.Empty; // OR string command = ""; OR string command = null;

            do
            {
                command = GetCommandFromInput(commands);
                ExecuteCommandWithReport(command, iphoneShop);
            } while (command != "quit");
            Console.ReadLine();
        }
Esempio n. 7
0
        private static void ExecuteCommandWithReport(string command, MobilePhoneShop iphoneShop)
        {
            string reportMessage;

            switch (command)
            {
            case "quit": {
                reportMessage = "=> Thank you. Good bye";
                break;
            }

            case "add store to shop": {
                reportMessage = AddStoreToShop(iphoneShop);
                break;
            }

            case "add phone to store": {
                reportMessage = AddPhoneToStore(iphoneShop);
                break;
            }

            case "show all phones in stores": {
                reportMessage = PrintStores(iphoneShop, true, true);
                break;
            }

            case "clear console": {
                Console.Clear();
                reportMessage = "=> Console cleared";
                break;
            }

            default: {
                reportMessage = "=> Unknown command is called";
                break;
            }
            }
            Console.WriteLine(reportMessage);
        }