public ShoppingListResult CreateShoppingList(AuthIdentity identity, ShoppingList list) { using (var session = GetSession()) { var ret = new ShoppingListResult(); using (var transaction = session.BeginTransaction()) { var dbList = new Models.ShoppingLists(); dbList.Title = list.Title.Trim(); dbList.UserId = identity.UserId; session.Save(dbList); if (list.Any()) // Create ShoppingListItems { list.ToList().ForEach(i => { var dbItem = ShoppingListItems.FromShoppingListItem(i); dbItem.ShoppingList = dbList; dbItem.UserId = dbList.UserId; session.Save(dbItem); }); } transaction.Commit(); ret.NewShoppingListId = dbList.ShoppingListId; } ret.List = list; return(ret); } }
//Return list of ingredients with sum values of quantity private static List <ShoppingListItems> sumQuantityShopping(List <Ingredient> listOfIngredients) { List <ShoppingListItems> listOfIngredients2 = new List <ShoppingListItems>(); var ingredientsGrouped = listOfIngredients.GroupBy(item => item.IngredientName); foreach (var items in listOfIngredients) { var sumItems = 0; foreach (var grp in ingredientsGrouped) { var key = grp.Key; var total = grp.Count(); if (items.IngredientName == key) { sumItems = items.Quantity * total; } } ShoppingListItems listItems = new ShoppingListItems { Name = items.IngredientName, Quantity = sumItems, Unit = items.Unit }; listOfIngredients2.Add(listItems); } return(listOfIngredients2); }
public ShoppingListPage() { InitializeComponent(); BindingContext = new ShoppingListView(); selectedItem = null; Today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); ExpDate = Today.Date.ToString("MM/dd"); }
/// <summary> /// Method to invoke when the Edit command is executed. /// </summary> /// <param name="parameter">The parameter of the command.</param> private void OnEditExecute(object parameter) { var parameters = new Dictionary <string, object>(); parameters.Add("ShoppingListIndex", _shoppingListIndex); parameters.Add("ShoppingListItemIndex", ShoppingListItems.IndexOf(SelectedShoppingListItem)); _navigationService.Navigate <ShoppingListItemViewModel>(parameters); }
public void EvaluateMaxIDs() { Ingredients.EvaluateMaxID(); FoodPlanItems.EvaluateMaxID(); Recipes.EvaluateMaxID(); Units.EvaluateMaxID(); UnitTranslations.EvaluateMaxID(); ShoppingListItems.EvaluateMaxID(); }
protected override async void OnAppearing() { base.OnAppearing(); ToggleCartAnimState(false, false); ToggleEditAnimState(false, false); await(BindingContext as ShoppingListView).RefreshList(); AnimButton.PlayFrameSegment(0, 25); CurrentFrame = 25; selectedItem = null; }
//Methods public void ClearList() { FoodPlanItems.Clear(); Ingredients.Clear(); Recipes.Clear(); ShoppingListItems.Clear(); Units.Clear(); UnitTranslations.Clear(); EvaluateMaxIDs(); }
}// --> View public override string ToString() { string ReturnString = ""; ReturnString += FoodPlanItems.ToString(); ReturnString += Ingredients.ToString(); ReturnString += Recipes.ToString(); ReturnString += Units.ToString(); ReturnString += UnitTranslations.ToString(); ReturnString += ShoppingListItems.ToString(); return(ReturnString); }
public async void GetInventoryItems() { try { AllInventoryItems = await BackendConn.GetInventory(); foreach (var inventoryItem in AllInventoryItems) { switch (inventoryItem.InventoryType) { case 0: FreezerItems.Add(inventoryItem.Item); break; case 1: FridgeItems.Add(inventoryItem.Item); break; case 2: PantryItems.Add(inventoryItem.Item); break; case 3: ShoppingListItems.Add(inventoryItem.Item); break; default: break; } AllItems.Add(inventoryItem.Item); inventoryItem.Category = GetCategory(inventoryItem.InventoryType); } ViewFilter = (CollectionView)CollectionViewSource.GetDefaultView(AllInventoryItems); ViewFilter.Filter = UserFilter; } catch (ApiException exception) { ItemNotFound(exception.StatusCode); } catch (HttpRequestException exception) { MessageBox.Show($"Der er ingen forbindele til serveren", "Error!"); } finally { RaisePropertyChanged("AllInventoryItems"); } }
private async void DatePicker_DateSelected(object sender, DateChangedEventArgs e) { await FirebaseHelper.AddPantryItem(selectedItem.ItemName, selectedItem.Amount, ExpDate); DateSelect.Date.ToString("MM/dd"); (BindingContext as ShoppingListView).Delete.Execute(selectedItem); AnimButton.PlayFrameSegment(45, 125); CartAnimButton.PlayFrameSegment(23, 120); // use in between frames when adding to pantry <3 CartAnimComplete = true; EditAnimButton.PlayFrameSegment(14, 48); EditAnimComplete = true; AnimButton.PlayFrameSegment(0, 25); CurrentFrame = 25; selectedItem = null; DateFrame.IsVisible = false; DateSelect.IsVisible = false; }
private void CollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e) { selectedItem = (e.CurrentSelection.FirstOrDefault() as ShoppingListItems); ToggleCartAnimState(true, false); CartAnimButton.PlayFrameSegment(0, 23); ToggleEditAnimState(true, false); EditAnimButton.PlayFrameSegment(0, 14); if (CurrentFrame == 25) { AnimButton.PlayFrameSegment(25, 45); CurrentFrame = 45; } }
private SettingsService() { _helper = new Template10.Services.SettingsService.SettingsHelper(); //Initialize GroceryItemTypes GroceryItemType[] savedGroceryTypes = _helper.Read(nameof(GroceryTypes), new GroceryItemType[] { new GroceryItemType("Milk, 1L"), new GroceryItemType("Bread"), new GroceryItemType("Cheese"), new GroceryItemType("Ketchup"), new GroceryItemType("Weiner schnitzel"), new GroceryItemType("Juice"), new GroceryItemType("Herb tomato pureƩ") }); _groceryTypes.AddRange(savedGroceryTypes); GroceryTypes = _groceryTypes.Connect(); //Initialize GroceryItems InventoryEntry[] savedInventory = _helper.Read(nameof(InventoryItems), new InventoryEntry[0]); _inventoryItems.AddRange(savedInventory); InventoryItems = _inventoryItems.Connect(); //Initialize ShoppingListItems ShoppingListEntry[] savedShoppingList = _helper.Read(nameof(ShoppingListItems), new ShoppingListEntry[0]); _shoppingListItems.AddRange(savedShoppingList); ShoppingListItems = _shoppingListItems.Connect(); //Write changes to Grocery Types 30 seconds after changes stop coming in GroceryTypes.Throttle(TimeSpan.FromSeconds(30)) .Subscribe( onNext: _ => _helper.Write(nameof(GroceryTypes), _groceryTypes.Items) ); //Write changes to Inventory Items to disk 30 seconds after changes stop coming in InventoryItems.Throttle(TimeSpan.FromSeconds(30)) .Subscribe( onNext: _ => _helper.Write(nameof(InventoryItems), _inventoryItems.Items) ); //Write changed to the Shopping List items to disk 30 seconds after changes stop coming in ShoppingListItems.Throttle(TimeSpan.FromSeconds(30)) .Subscribe( onNext: _ => _helper.Write(nameof(ShoppingListItems), _shoppingListItems.Items) ); }
private async void AddDeleteButton_Clicked(object sender, EventArgs e) { if (CurrentFrame == 25) { await Shell.Current.GoToAsync("ShoppingAddItem"); } else if (CurrentFrame == 45) { (BindingContext as ShoppingListView).Delete.Execute(selectedItem); AnimButton.PlayFrameSegment(45, 125); CartAnimButton.PlayFrameSegment(98, 120); // use in between frames when adding to pantry <3 CartAnimComplete = true; EditAnimButton.PlayFrameSegment(14, 48); EditAnimComplete = true; AnimButton.PlayFrameSegment(0, 25); CurrentFrame = 25; selectedItem = null; } }
public async void HandleDelete(ShoppingListItems items) { await FirebaseHelper.DeleteShoppingList(items.ItemName); await RefreshList(); }
public ShoppingListResult UpdateShoppingList( AuthIdentity identity, Guid? listId, Guid[] toRemove, ShoppingListModification[] toModify, IShoppingListSource[] toAdd, string newName = null) { using (var session = this.GetSession()) { using (var transaction = session.BeginTransaction()) { // Deletes if (toRemove.Any()) { var itemsToDelete = session.QueryOver<ShoppingListItems>() .Where(p => p.UserId == identity.UserId) .Where(listId.HasValue ? Restrictions.Eq("ShoppingList", listId.Value) : Restrictions.IsNull("ShoppingList")) .AndRestrictionOn(p => p.ItemId) .IsInG(toRemove) .List(); itemsToDelete.ForEach(session.Delete); } // Updates ShoppingLists shoppingList = null; IList<ShoppingListItems> shoppingListItems; if (listId.HasValue) { shoppingList = session.QueryOver<ShoppingLists>() .Fetch(prop => prop.Items).Eager .Where(p => p.UserId == identity.UserId) .Where(p => p.ShoppingListId == listId.Value) .SingleOrDefault(); if (shoppingList == null) { throw new ShoppingListNotFoundException(); } if (!string.IsNullOrWhiteSpace(newName)) { shoppingList.Title = newName; } shoppingListItems = shoppingList.Items; } else { shoppingListItems = session.QueryOver<ShoppingListItems>() .Where(p => p.UserId == identity.UserId) .Where(p => p.ShoppingList == null) .List(); } toModify.ForEach(item => { var dbItem = shoppingListItems.FirstOrDefault(i => i.ItemId == item.ModifiedItemId); if (dbItem == null) { return; } if (item.CrossOut.HasValue) { dbItem.CrossedOut = item.CrossOut.Value; } if (item.NewAmount != null) { dbItem.Amount = item.NewAmount; } }); toAdd.ForEach(item => { var source = item.GetItem(); if (source.Ingredient == null && !string.IsNullOrWhiteSpace(source.Raw)) // Raw shopping list item { if (!shoppingListItems.Any(i => source.Raw.Equals(i.Raw, StringComparison.OrdinalIgnoreCase))) // Add it { var newItem = new ShoppingListItems { ShoppingList = shoppingList, UserId = identity.UserId, Raw = source.Raw }; session.Save(newItem); shoppingListItems.Add(newItem); } return; } // TODO: Extract unknow method... Name it somehow if (source.Ingredient != null && source.Amount == null) // Raw ingredient without any amount { var existingItem = shoppingListItems.FirstOrDefault(i => i.Ingredient != null && i.Ingredient.IngredientId == source.Ingredient.Id); if (existingItem == null) { var newItem = new ShoppingListItems { ShoppingList = shoppingList, UserId = identity.UserId, Ingredient = Ingredients.FromId(source.Ingredient.Id) }; session.Save(newItem); shoppingListItems.Add(newItem); } else { existingItem.Amount = null; } } if (source.Ingredient != null && source.Amount != null) // Ingredient with amount, aggregate if necessary { var existingItem = shoppingListItems.FirstOrDefault(i => i.Ingredient != null && i.Ingredient.IngredientId == source.Ingredient.Id); if (existingItem == null) { var newItem = new ShoppingListItems { ShoppingList = shoppingList, UserId = identity.UserId, Ingredient = Models.Ingredients.FromId(source.Ingredient.Id), Amount = source.Amount }; session.Save(newItem); shoppingListItems.Add(newItem); } else if (existingItem.Amount != null) // Add to total { existingItem.Amount += source.Amount; } } }); transaction.Commit(); return new ShoppingListResult { List = new ShoppingList( shoppingList != null ? (Guid?)shoppingList.ShoppingListId : null, shoppingList != null ? shoppingList.Title : null, shoppingListItems.Select(i => i.AsShoppingListItem())) }; } } }
public ShoppingListResult UpdateShoppingList(AuthIdentity identity, Guid?listId, Guid[] toRemove, ShoppingListModification[] toModify, IShoppingListSource[] toAdd, string newName = null) { using (var session = GetSession()) { using (var transaction = session.BeginTransaction()) { // Deletes if (toRemove.Any()) { var dbDeletes = session.QueryOver <ShoppingListItems>() .Where(p => p.UserId == identity.UserId) .Where(listId.HasValue ? Expression.Eq("ShoppingList", listId.Value) : Expression.IsNull("ShoppingList") ).AndRestrictionOn(p => p.ItemId).IsInG(toRemove) .List(); dbDeletes.ForEach(session.Delete); } // Updates Models.ShoppingLists dbList = null; IList <ShoppingListItems> dbItems = null; if (listId.HasValue) { dbList = session.QueryOver <Models.ShoppingLists>() .Fetch(prop => prop.Items).Eager .Where(p => p.UserId == identity.UserId) .Where(p => p.ShoppingListId == listId.Value) .SingleOrDefault(); if (dbList == null) { throw new ShoppingListNotFoundException(); } if (!String.IsNullOrWhiteSpace(newName)) { dbList.Title = newName; } dbItems = dbList.Items; } else { dbItems = session.QueryOver <ShoppingListItems>() .Where(p => p.UserId == identity.UserId) .Where(p => p.ShoppingList == null) .List(); } toModify.ForEach(item => { var dbItem = dbItems.FirstOrDefault(i => i.ItemId == item.ModifiedItemId); if (dbItem == null) { return; } if (item.CrossOut.HasValue) { dbItem.CrossedOut = item.CrossOut.Value; } if (item.NewAmount != null) { dbItem.Amount = item.NewAmount; } }); toAdd.ForEach(item => { var source = item.GetItem(); if (source.Ingredient == null && !String.IsNullOrWhiteSpace(source.Raw)) // Raw shopping list item { if (!dbItems.Any(i => source.Raw.Equals(i.Raw, StringComparison.OrdinalIgnoreCase))) // Add it { var newItem = new ShoppingListItems { ShoppingList = dbList, UserId = identity.UserId, Raw = source.Raw }; session.Save(newItem); dbItems.Add(newItem); } return; } if (source.Ingredient != null && source.Amount == null) // Raw ingredient without any amount { var existingItem = dbItems.FirstOrDefault(i => i.Ingredient != null && i.Ingredient.IngredientId == source.Ingredient.Id); if (existingItem == null) // Add it { var newItem = new ShoppingListItems { ShoppingList = dbList, UserId = identity.UserId, Ingredient = Models.Ingredients.FromId(source.Ingredient.Id) }; session.Save(newItem); dbItems.Add(newItem); } else // Clear out existing amount { existingItem.Amount = null; } } if (source.Ingredient != null && source.Amount != null) // Ingredient with amount, aggregate if necessary { var existingItem = dbItems.FirstOrDefault(i => i.Ingredient != null && i.Ingredient.IngredientId == source.Ingredient.Id); if (existingItem == null) // Add it { var newItem = new ShoppingListItems { ShoppingList = dbList, UserId = identity.UserId, Ingredient = Models.Ingredients.FromId(source.Ingredient.Id), Amount = source.Amount }; session.Save(newItem); dbItems.Add(newItem); } else if (existingItem.Amount != null) // Add to total { existingItem.Amount += source.Amount; } } }); transaction.Commit(); return(new ShoppingListResult { List = new ShoppingList( dbList != null ? (Guid?)dbList.ShoppingListId : null, dbList != null ? dbList.Title : null, dbItems.Select(i => i.AsShoppingListItem())) }); } } }