public bool AddPhoneToStore(MobilePhone phone) { for (int i = 0; i < Phones.Length; i++) { if (Phones[i] == null) { Phones[i] = phone; return(true); } } return(false); }
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()}'."); }
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); }