Example #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);
        }
Example #2
0
        private static string AddStoreToShop(MobilePhoneShop iphoneShop)
        {
            MobilePhoneStore mobilePhoneStore = CreateMobilePhoneStoreFromInput();

            iphoneShop.AddStore(mobilePhoneStore);
            return($"=> Shop '{mobilePhoneStore.GetDescription()}' successfully created.");
        }
 internal void AddStore(MobilePhoneStore iPhoneStore)
 {
     for (int i = 0; i < MobilePhoneStores.Length; i++)
     {
         if (MobilePhoneStores[i] == null)
         {
             MobilePhoneStores[i] = iPhoneStore;
             break;
         }
     }
 }
Example #4
0
        private static void PrintAllPhonesInStore(MobilePhoneStore mobilePhoneStore)
        {
            int currentPhoneIndex = 0;

            foreach (var phone in mobilePhoneStore.Phones)
            {
                string stringToShow = $"   [{currentPhoneIndex}] - Phone cell is ";
                stringToShow += phone == null ? "empty" : $"'{phone.GetDescription()}'";
                Console.WriteLine(stringToShow);
                currentPhoneIndex++;
            }
        }
Example #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()}'.");
        }