コード例 #1
0
 public bool AddPhoneToStore(MobilePhone phone)
 {
     for (int i = 0; i < Phones.Length; i++)
     {
         if (Phones[i] == null)
         {
             Phones[i] = phone;
             return(true);
         }
     }
     return(false);
 }
コード例 #2
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()}'.");
        }
コード例 #3
0
        internal bool AddPhoneToStore(MobilePhone phone, string address)
        {
            foreach (var phoneStore in MobilePhoneStores)
            {
                if (phoneStore == null)
                {
                    continue;
                }

                if (phoneStore.Address == address)
                {
                    return(phoneStore.AddPhoneToStore(phone));
                }
            }
            return(false);
        }