예제 #1
0
        public IActionResult SubmitToShoppingList(string Monday, string Tuesday, string Wednesday, string Thursday, string Friday, string Saturday, string Sunday, string User)
        {
            try
            {
                var monday    = GetIngredients(Monday);
                var tuesday   = GetIngredients(Tuesday);
                var wednesday = GetIngredients(Wednesday);
                var thursday  = GetIngredients(Thursday);
                var friday    = GetIngredients(Friday);
                var saturday  = GetIngredients(Saturday);
                var sunday    = GetIngredients(Sunday);


                List <Ingredient> listOfIngredients = new List <Ingredient>();
                listOfIngredients.AddRange(monday);
                listOfIngredients.AddRange(tuesday);
                listOfIngredients.AddRange(wednesday);
                listOfIngredients.AddRange(thursday);
                listOfIngredients.AddRange(friday);
                listOfIngredients.AddRange(saturday);
                listOfIngredients.AddRange(sunday);

                List <ShoppingListItems> listOfIngredients2 = sumQuantityShopping(listOfIngredients);

                var updateOptions = new UpdateOptions {
                    IsUpsert = true
                };                                                         //insert new document if non existing
                var shoppingItems = CosmoDBConection.GetShoppingItems();
                var filter        = Builders <ShoppingListModel> .Filter.Eq("user", User);

                shoppingItems.FindOneAndDelete(filter);                                                             //delete exisiting list

                var update = Builders <ShoppingListModel> .Update.AddToSetEach("shoppingList", listOfIngredients2); //update existing/create new list with shopping list

                shoppingItems.UpdateOne(filter, update, updateOptions);

                return(RedirectToAction("ContentAndShopping"));
            }
            catch
            {
                return(RedirectToAction("Planner"));//return Planer page if any exception is thrown
            }
        }
예제 #2
0
 public WebRecipesController()
 {
     _recipes      = CosmoDBConection.GetRecipes();
     _fridge       = CosmoDBConection.GetFridge();
     _shoppingList = CosmoDBConection.GetShoppingItems();
 }