/// <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> /// Removes a <c>Shop</c>-Object from the <c>Shops</c>-Collection. /// </summary> /// <param name="shop">The <c>Shop</c>-Object that should be removed from the Collection.</param> public void DeleteShop(Shop shop) { Shops.Remove(shop); // 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(shop.ID)) { ShoppingLists.Remove(list); } } // Save data to isolated storage SaveShops(); SaveShoppingLists(); // Remove Geofence ServiceLocator.Current.GetInstance <GeoHelper>().RemoveGeofence(shop.ID); }