Example #1
0
        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);
            }
        }
Example #2
0
        //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);
        }
Example #3
0
 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);
        }
Example #5
0
 public void EvaluateMaxIDs()
 {
     Ingredients.EvaluateMaxID();
     FoodPlanItems.EvaluateMaxID();
     Recipes.EvaluateMaxID();
     Units.EvaluateMaxID();
     UnitTranslations.EvaluateMaxID();
     ShoppingListItems.EvaluateMaxID();
 }
Example #6
0
 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;
 }
Example #7
0
 //Methods
 public void ClearList()
 {
     FoodPlanItems.Clear();
     Ingredients.Clear();
     Recipes.Clear();
     ShoppingListItems.Clear();
     Units.Clear();
     UnitTranslations.Clear();
     EvaluateMaxIDs();
 }
Example #8
0
        }// --> 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);
        }
Example #9
0
        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");
            }
        }
Example #10
0
        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;
        }
Example #11
0
        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;
            }
        }
Example #12
0
        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)
                );
        }
Example #13
0
 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;
     }
 }
Example #14
0
        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()))
                    };
                }
            }
        }
Example #16
0
        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()))
                    });
                }
            }
        }