/// <summary> /// Replaces an old <c>Shop</c>-Object with a modified one. /// </summary> /// <param name="oldShop">The <c>Shop</c>-Object that should be replaced.</param> /// <param name="newShop">The <c>Shop</c>-Object that should be inserted into the Collection.</param> public void EditShop(Shop oldShop, Shop newShop) { // Get index of old object int idx = Shops.IndexOf(oldShop); // Clone ShoppingLists-List var templist = ShoppingLists.ToList(); // Query all shopping lists and update the Shop object of the Shopping lists foreach (ShoppingList list in templist) { if (list.Shop.ID.Equals(oldShop.ID)) { // Get index of old object int listIdx = ShoppingLists.IndexOf(list); // Set new shop list.Shop = newShop; // Remove old object from list and insert new one ShoppingLists.RemoveAt(listIdx); ShoppingLists.Insert(listIdx, list); } } // Remove old object and insert new object at the same position as the old one Shops.Remove(oldShop); Shops.Insert(idx, newShop); // Save data to isolated storage SaveShops(); SaveShoppingLists(); // Replace old Geofence with new one ServiceLocator.Current.GetInstance <GeoHelper>().ModifyGeofence(oldShop.ID, newShop); }
/// <summary> /// Replaces an old <c>ShoppingList</c>-Object with a modified one. /// </summary> /// <param name="oldShoppingList">The <c>Shop</c>-Object that should be replaced.</param> /// <param name="newShoppingList">The <c>Shop</c>-Object that should be inserted into the Collection.</param> public void EditShoppingList(ShoppingList oldShoppingList, ShoppingList newShoppingList) { // Get index of old object int idx = ShoppingLists.IndexOf(oldShoppingList); // Remove old object and insert new object at the same position as the old one ShoppingLists.Remove(oldShoppingList); ShoppingLists.Insert(idx, newShoppingList); // Save data to isolated storage SaveShoppingLists(); }
public void AddItem() { if (!string.IsNullOrWhiteSpace(_searchString) && _searchString.Length > 2) { var newList = new ShoppingList() { Name = _searchString }; ShoppingLists.Insert(0, newList); Device.BeginInvokeOnMainThread(async() => { Clear(); _shoppingService.AddList(newList); await LoadData(); }); } }