예제 #1
0
 public void SaveEdits(Items newItem, string URL)
 {
     using (var _groceryRepoItems = new GroceryContext())
     {
         var          itemToEdit       = _groceryRepoItems.GroceryItems.SingleOrDefault(x => x.Id == newItem.Id);
         AdminAddItem saveImageForItem = new AdminAddItem();
         if (URL != "")
         {
             saveImageForItem.CoverImageURL(newItem.ItemName, URL);
         }
         if (itemToEdit != newItem)
         {
             if (itemToEdit.ItemName != newItem.ItemName && URL == "")
             {
                 saveImageForItem.UpdateImageLocation(itemToEdit.ItemName, newItem.ItemName);
             }
             if (newItem.Type == null)
             {
                 newItem.Type = itemToEdit.Type;
             }
             if (newItem.Food == null)
             {
                 newItem.Food = itemToEdit.Food;
             }
             if (newItem.ItemName == null)
             {
                 newItem.ItemName = itemToEdit.ItemName;
             }
             _groceryRepoItems.GroceryItems.Remove(itemToEdit);
             _groceryRepoItems.GroceryItems.Add(newItem);
             _groceryRepoItems.SaveChanges();
         }
     }
 }
예제 #2
0
        public ActionResult GroceryCategories(string startsWith = null, string contains = null, int maxCount = 10)
        {
            JsGroceryResults groceryResults = new JsGroceryResults();
            var           context           = new GroceryContext();
            List <string> categories        = new List <string>();

            var possibleCategories = context.GroceryCategories.Where(g => g.Name.StartsWith(startsWith) || g.Name.Contains(contains)).ToList();

            foreach (var category in possibleCategories)
            {
                if (startsWith == null ||
                    category.Name.StartsWith(startsWith, StringComparison.OrdinalIgnoreCase) ||
                    (contains != null && category.Name.Contains(contains)))
                {
                    categories.Add(category.Name);
                }
                if (categories.Count == maxCount)
                {
                    break;
                }
            }

            groceryResults.Count     = categories.Count;
            groceryResults.Groceries = categories;

            JsonResult result = new JsonResult();

            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            result.Data = groceryResults;
            return(result);
        }
예제 #3
0
        public ActionResult GroceryInfo(string name)
        {
            ServiceHost.TraceLog.TraceDetail("GroceryInfo called with " + name);
            JsGroceryResults groceryResults = new JsGroceryResults();
            var context = new GroceryContext();
            List <GroceryReturnValue> grocery = new List <GroceryReturnValue>();
            var groceryName = name.ToLower();

            try
            {
                var groc = context.Groceries.Include("Category").OrderBy(g => g.Name).First(g => g.Name.StartsWith(groceryName));
                grocery.Add(new GroceryReturnValue()
                {
                    Name = groc.Name, Category = groc.Category.Name, ImageUrl = groc.ImageUrl
                });
                ServiceHost.TraceLog.TraceDetail(String.Format("Found {0} category for {1}", groc.Category.Name, name));
            }
            catch (Exception)
            {
                ServiceHost.TraceLog.TraceDetail("Could not find a category for " + name);
            }

            groceryResults.Count     = grocery.Count;
            groceryResults.Groceries = grocery;

            JsonResult result = new JsonResult();

            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            result.Data = groceryResults;
            return(result);
        }
예제 #4
0
        public ActionResult Plant(string Item)
        {
            //gets id number from string post
            int id = Int32.Parse(Item);

            if (ModelState.IsValid)
            {
                using (var _groceryRepoItems = new GroceryContext())
                {
                    Items            inventoryItem = _groceryRepoItems.GroceryItems.SingleOrDefault(m => m.Id == id);
                    ShoppingCartItem addThis       = new ShoppingCartItem
                    {
                        Item = inventoryItem
                    };
                    _groceryRepoItems.ShoppingCartItems.Add(addThis);
                    inventoryItem.Quantity -= 1;
                    _groceryRepoItems.SaveChanges();
                }
                return(RedirectToAction("Plant"));
            }
            else
            {
                return(View());
            }
        }
예제 #5
0
 public ActionResult Recipes(string recipeName)
 {
     if (ModelState.IsValid)
     {
         using (var _groceryRepoItems = new GroceryContext())
         {
             var matchRecipeName = _groceryRepoItems.ListOfRecipes.SingleOrDefault(m => m.RecipeName == recipeName);
             foreach (var name in matchRecipeName.Item)
             {
                 Items            inventoryItem = _groceryRepoItems.GroceryItems.SingleOrDefault(m => m.ItemName == name.ItemName);
                 ShoppingCartItem addThis       = new ShoppingCartItem
                 {
                     Item = inventoryItem
                 };
                 _groceryRepoItems.ShoppingCartItems.Add(addThis);
                 inventoryItem.Quantity -= 1;
                 _groceryRepoItems.SaveChanges();
             }
         }
         return(RedirectToAction("Recipes"));
     }
     else
     {
         return(View());
     }
 }
 public AddIngredientList()
 {
     using (var _groceryRepoItems = new GroceryContext())
     {
         var inventory       = _groceryRepoItems.GroceryItems.ToArray();
         var recipeListNames = _groceryRepoItems.ListOfRecipes.ToArray();
         if (recipeListNames.Length == 2)
         {
             List <List <string> > initialIngredientList = new List <List <string> > {
             };
             List <string> potatoSoupIds = new List <string> {
                 "Potato Soup", "Potato", "Milk", "Butter", "Pepper", "Salt", "Bacon", "Celery", "Onion", "Vegetable Broth"
             };
             List <string> chicBrocRice = new List <string> {
                 "Chicken Broccoli Rice", "Chicken Breast", "White Rice", "Broccoli", "Pepper", "Vegetable Broth", "Salt"
             };
             initialIngredientList.Add(potatoSoupIds);
             initialIngredientList.Add(chicBrocRice);
             foreach (var oneRecipe in recipeListNames)
             {
                 if (oneRecipe.Item.Count == 0)
                 {
                     foreach (var ingredientList in initialIngredientList)
                     {
                         AddIngredients(ingredientList);
                     }
                     ;
                 }
             }
         }
     }
 }
예제 #7
0
 public ShopService(GroceryContext db, IMapper mapper, AppIdentityDbContext identity, IUriComposer uriComposer)
 {
     _db          = db;
     _mapper      = mapper;
     _identityDb  = identity;
     _uriComposer = uriComposer;
 }
 public ActionResult Baking()
 {
     ViewBag.Message = "Items You Need to Bake, Season, and Create Deliciousness";
     using (var _groceryRepoItems = new GroceryContext())
     {
         return(View(_groceryRepoItems.GroceryItems.ToArray()));
     }
 }
 public ActionResult Meat()
 {
     ViewBag.Message = "Animal Protein to Refuel";
     using (var _groceryRepoItems = new GroceryContext())
     {
         return(View(_groceryRepoItems.GroceryItems.ToArray()));
     }
 }
 public ActionResult Plant()
 {
     ViewBag.Message = "Food You Need to Feel Healthy and Live Well";
     //loads plant page with full array of grocery items
     using (var _groceryRepoItems = new GroceryContext())
     {
         return(View(_groceryRepoItems.GroceryItems.ToArray()));
     }
 }
예제 #11
0
 public HomeController()
 {
     //creates shopping cart array for viewbag prop
     using (var _shoppingCart = new GroceryContext())
     {
         var shoppingCartQuery = from ci in _shoppingCart.ShoppingCartItems select ci;
         var shoppingCartList  = shoppingCartQuery.ToList();
         ViewBag._shoppingCart = shoppingCartList.ToArray();
     }
 }
예제 #12
0
 public ActionResult ShoppingCart(int ItemId, string math)
 {
     if (ModelState.IsValid)
     {
         using (var _shoppingCartItems = new GroceryContext())
         {
             //gets the item from inventory
             Items inventoryItem = _shoppingCartItems.GroceryItems.SingleOrDefault(m => m.Id == ItemId);
             //finds item to be removed
             ShoppingCartItem itemRemove = _shoppingCartItems.ShoppingCartItems.FirstOrDefault(m => m.ItemId == ItemId);
             //transforms inventory item to shopping cart item
             ShoppingCartItem cartItem = new ShoppingCartItem
             {
                 Item = inventoryItem
             };
             if (math == "add")
             {
                 _shoppingCartItems.ShoppingCartItems.Add(cartItem);
                 //logic for when quantity reduction goes over quantity amount is not yet created.
                 inventoryItem.Quantity -= 1;
                 _shoppingCartItems.SaveChanges();
             }
             else if (math == "sub")
             {
                 _shoppingCartItems.ShoppingCartItems.Remove(itemRemove);
                 inventoryItem.Quantity += 1;
                 _shoppingCartItems.SaveChanges();
             }
             else if (math == "del")
             {
                 //removes all instances of item in shopping cart. probably a better way to do this.
                 foreach (var item in _shoppingCartItems.ShoppingCartItems)
                 {
                     if (item.ItemId == ItemId)
                     {
                         _shoppingCartItems.ShoppingCartItems.Remove(item);
                         inventoryItem.Quantity += 1;
                     }
                 }
                 _shoppingCartItems.SaveChanges();
             }
             //deletes all items from shopping cart. ItemId is a potential placemarker for shopping cart id
             else if (math == "checkout" && ItemId == 000)
             {
                 foreach (var item in _shoppingCartItems.ShoppingCartItems)
                 {
                     _shoppingCartItems.ShoppingCartItems.Remove(item);
                 }
                 _shoppingCartItems.SaveChanges();
             }
             return(RedirectToAction("ShoppingCart"));
         }
     }
     return(View());
 }
예제 #13
0
 static HomeController()
 {
     using (var _groceryRepoItems = new GroceryContext())
     {
         var recipeCheck = _groceryRepoItems.ListOfRecipes.ToArray();
         if (recipeCheck[0].Item.Count == 0)
         {
             AddIngredientList addInitialRecipe = new AddIngredientList();
         }
     }
 }
예제 #14
0
        public GroceryController(GroceryContext context)
        {
            _context = context;

            if (_context.GroceryItems.Count() == 0)
            {
                _context.GroceryItems.Add(new GroceryItem {
                    Name = "Milk", Quantity = 1, Unit = "Gallon"
                });
                _context.SaveChanges();
            }
        }
예제 #15
0
        public ActionResult UpdateInventory(Items newItem, string URL)
        {
            AdminAddItem saveImageForItem = new AdminAddItem();

            saveImageForItem.CoverImageURL(newItem.ItemName, URL);
            using (var _groceryRepoItems = new GroceryContext())
            {
                _groceryRepoItems.GroceryItems.Add(newItem);
                _groceryRepoItems.SaveChanges();
            }
            ViewBag.Message = "Item Saved.";
            return(View());
        }
예제 #16
0
        public DatabaseFixture()
        {
            bCryptPasswordHasher = new PasswordHasher(new PasswordSettings {
                SecretKey = "$2y$12$1YIOnDli2aDPGVSrpCBEt.tjEgcK1tX6.a/6yVp9l4h6Crc9UHeHW"
            });
            var dbContextOptions = new DbContextOptionsBuilder <GroceryContext>().UseInMemoryDatabase("TestDB");

            Context = new GroceryContext(dbContextOptions.Options, new Common.SeedWork.DatabaseSettings {
                InMemory = true
            });
            Context.Database.EnsureCreated();
            Setup();
        }
예제 #17
0
        private readonly GroceryContext _db; //TODO move all queries to repo

        public CatalogService(
            ILoggerFactory loggerFactory,
            IAsyncRepository <CatalogItem> itemRepository,
            IAsyncRepository <CatalogIllustration> illustrationRepository,
            IAsyncRepository <CatalogType> typeRepository,
            IUriComposer uriComposer,
            GroceryContext db)
        {
            _logger                 = loggerFactory.CreateLogger <CatalogService>();
            _itemRepository         = itemRepository;
            _illustrationRepository = illustrationRepository;
            _typeRepository         = typeRepository;
            _uriComposer            = uriComposer;
            _db = db;
        }
예제 #18
0
        public void AddFromForm()
        {
            AddIngredientList stubToUse      = new AddIngredientList();
            List <string>     ingredientList = new List <string> {
                Name, Beef, Chicken, Grain, Ingredient, Ingredients, Other, Pork, Vegetable, Vegetables
            };

            stubToUse.AddIngredients(ingredientList);
            using (var recipeRepoItems = new GroceryContext())
            {
                var wayToAddDes = recipeRepoItems.ListOfRecipes.SingleOrDefault(x => x.RecipeName == Name);
                wayToAddDes.Description = Description;
                recipeRepoItems.SaveChanges();
            }
        }
 public List <SelectListItem> GetGroceryList()
 {
     using (var inventory = new GroceryContext())
     {
         var getInventoryList = inventory.GroceryItems.ToList();
         List <SelectListItem> inventoryItemsList = new List <SelectListItem>();
         foreach (var stock in getInventoryList)
         {
             var addItem = new SelectListItem {
                 Text = stock.ItemName, Value = stock.Id.ToString()
             };
             inventoryItemsList.Add(addItem);
         }
         return(inventoryItemsList);
     }
 }
예제 #20
0
 public void RemoveTheseItems()
 {
     using (var _groceryList = new GroceryContext())
     {
         if (Beef != null)
         {
             var beefRem = _groceryList.GroceryItems.SingleOrDefault(x => x.ItemName == Beef);
             _groceryList.GroceryItems.Remove(beefRem);
         }
         if (Chicken != null)
         {
             var chicRem = _groceryList.GroceryItems.SingleOrDefault(x => x.ItemName == Chicken);
             _groceryList.GroceryItems.Remove(chicRem);
         }
         if (Grain != null)
         {
             var graRem = _groceryList.GroceryItems.SingleOrDefault(x => x.ItemName == Grain);
             _groceryList.GroceryItems.Remove(graRem);
         }
         if (Ingredient != null)
         {
             var ingRem = _groceryList.GroceryItems.SingleOrDefault(x => x.ItemName == Ingredient);
             _groceryList.GroceryItems.Remove(ingRem);
         }
         if (Other != null)
         {
             var othRem = _groceryList.GroceryItems.SingleOrDefault(x => x.ItemName == Other);
             _groceryList.GroceryItems.Remove(othRem);
         }
         if (Pork != null)
         {
             var porkRem = _groceryList.GroceryItems.SingleOrDefault(x => x.ItemName == Pork);
             _groceryList.GroceryItems.Remove(porkRem);
         }
         if (Vegetable != null)
         {
             var vegeRem = _groceryList.GroceryItems.SingleOrDefault(x => x.ItemName == Vegetable);
             _groceryList.GroceryItems.Remove(vegeRem);
         }
         if (Fruit != null)
         {
             var fruitRem = _groceryList.GroceryItems.SingleOrDefault(x => x.ItemName == Fruit);
             _groceryList.GroceryItems.Remove(fruitRem);
         }
         _groceryList.SaveChanges();
     }
 }
예제 #21
0
        public ActionResult GroceryNames(string startsWith = null, string contains = null, int maxCount = 10)
        {
            JsGroceryResults groceryResults = new JsGroceryResults();
            var context = new GroceryContext();
            List <GroceryReturnValue> groceries = new List <GroceryReturnValue>();

            List <Grocery> possibleGroceryNames;

            if (startsWith != null)
            {   // filter by startsWith
                possibleGroceryNames = context.Groceries.Include("Category").Where(g => g.Name.StartsWith(startsWith)).ToList();
            }
            else
            {   // get all and post-filter
                possibleGroceryNames = context.Groceries.Include("Category").ToList();
            }

            contains = (contains != null) ? contains.ToLowerInvariant() : null;
            foreach (var grocery in possibleGroceryNames)
            {
                if (contains == null || grocery.Name.Contains(contains))
                {   // upper-case each word in name and add to results
                    var groceryName  = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(grocery.Name);
                    var groceryValue = new GroceryReturnValue()
                    {
                        Name = groceryName, Category = grocery.Category.Name
                    };
                    groceryValue.ImageUrl = (!string.IsNullOrEmpty(grocery.ImageUrl)) ? grocery.ImageUrl : null;
                    groceries.Add(groceryValue);
                }
                if (groceries.Count == maxCount)
                {
                    break;
                }
            }

            groceryResults.Count     = groceries.Count;
            groceryResults.Groceries = groceries;

            JsonResult result = new JsonResult();

            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            result.Data = groceryResults;
            return(result);
        }
예제 #22
0
        public void TransformItem(string Id, string UserName)
        {
            //gets id number from string post
            int id = Int32.Parse(Id);

            using (var _groceryRepoItems = new GroceryContext())
            {
                Items            inventoryItem = _groceryRepoItems.GroceryItems.SingleOrDefault(m => m.Id == id);
                ShoppingCartItem addThis       = new ShoppingCartItem
                {
                    Item = inventoryItem
                };
                addThis.UserId = UserName;
                _groceryRepoItems.ShoppingCartItems.Add(addThis);
                inventoryItem.Quantity -= 1;
                _groceryRepoItems.SaveChanges();
            }
        }
        public void AdjustCart(int ItemId, string user, string math)
        {
            using (var _shoppingCartItems = new GroceryContext())
            {
                //gets the item from inventory
                Items inventoryItem = _shoppingCartItems.GroceryItems.SingleOrDefault(m => m.Id == ItemId);
                //finds item to be removed
                ShoppingCartItem itemRemove = _shoppingCartItems.ShoppingCartItems.FirstOrDefault(m => m.ItemId == ItemId);

                if (math == "add")
                {
                    var    changeItems      = new ItemToShoppingCartItemFactory();
                    string changeIdToString = ItemId.ToString();
                    changeItems.TransformItem(changeIdToString, user);
                }
                else if (math == "sub")
                {
                    _shoppingCartItems.ShoppingCartItems.Remove(itemRemove);
                    inventoryItem.Quantity += 1;
                    _shoppingCartItems.SaveChanges();
                }
                else if (math == "del")
                {
                    foreach (var item in _shoppingCartItems.ShoppingCartItems)
                    {
                        if (item.ItemId == ItemId)
                        {
                            _shoppingCartItems.ShoppingCartItems.Remove(item);
                            inventoryItem.Quantity += 1;
                        }
                    }
                    _shoppingCartItems.SaveChanges();
                }
                //deletes all items from shopping cart. ItemId is a potential placemarker for shopping cart id
                else if (math == "checkout" && ItemId == 000)
                {
                    foreach (var item in _shoppingCartItems.ShoppingCartItems)
                    {
                        _shoppingCartItems.ShoppingCartItems.Remove(item);
                    }
                    _shoppingCartItems.SaveChanges();
                }
            }
        }
 public ActionResult Recipes(string recipeName)
 {
     if (ModelState.IsValid)
     {
         using (var _groceryRepoItems = new GroceryContext())
         {
             var matchRecipeName = _groceryRepoItems.ListOfRecipes.SingleOrDefault(m => m.RecipeName == recipeName);
             var ItemToShoppingCartItemFactory = new ItemToShoppingCartItemFactory();
             var user = User.Identity.Name;
             foreach (var name in matchRecipeName.Item)
             {
                 ItemToShoppingCartItemFactory.TransformItem(name.Id.ToString(), user);
             }
         }
         return(RedirectToAction("Recipes"));
     }
     else
     {
         return(View());
     }
 }
 public List <SelectListItem> GetGroceryTypes()
 {
     using (var inventory = new GroceryContext())
     {
         var                   getInventoryList = inventory.GroceryItems.ToList();
         List <string>         stringTypes      = new List <string>();
         List <SelectListItem> inventoryTypes   = new List <SelectListItem>();
         foreach (var stock in getInventoryList)
         {
             var typeInList = stringTypes.SingleOrDefault(x => x == stock.Type);
             if (typeInList == null)
             {
                 stringTypes.Add(stock.Type);
                 var nextType = new SelectListItem {
                     Text = stock.Type, Value = stock.Type
                 };
                 inventoryTypes.Add(nextType);
             }
         }
         return(inventoryTypes);
     }
 }
 public List <SelectListItem> GetGroceryFoods()
 {
     using (var inventory = new GroceryContext())
     {
         var                   getInventoryList        = inventory.GroceryItems.ToList();
         List <string>         stringCategories        = new List <string>();
         List <SelectListItem> inventoryFoodCategories = new List <SelectListItem>();
         foreach (var stock in getInventoryList)
         {
             var foodInList = stringCategories.SingleOrDefault(x => x == stock.Food);
             if (foodInList == null)
             {
                 stringCategories.Add(stock.Food);
                 var nextFoodCategory = new SelectListItem {
                     Text = stock.Food, Value = stock.Food
                 };
                 inventoryFoodCategories.Add(nextFoodCategory);
             }
         }
         return(inventoryFoodCategories);
     }
 }
        public void AddIngredients(List <string> ingredientList)
        {
            using (var _groceryRepoItems = new GroceryContext())
            {
                var inventory  = _groceryRepoItems.GroceryItems.ToArray();
                var recipeList = _groceryRepoItems.ListOfRecipes.ToArray();
                var oneRecipe  = recipeList.SingleOrDefault(x => x.RecipeName == ingredientList[0]);

                List <Items> updateList = new List <Items> {
                };
                foreach (var ingredient in ingredientList)
                {
                    var addThis = inventory.SingleOrDefault(x => x.ItemName == ingredient);
                    if (addThis != null)
                    {
                        updateList.Add(addThis);
                    }
                }

                if (oneRecipe != null)
                {
                    oneRecipe.Item = updateList;
                    _groceryRepoItems.SaveChanges();
                }
                if (oneRecipe == null)
                {
                    string      recipeName = ingredientList[0];
                    RecipeItems newRecipe  = new RecipeItems()
                    {
                        RecipeName = recipeName
                    };
                    newRecipe.Item = updateList;
                    _groceryRepoItems.ListOfRecipes.Add(newRecipe);
                    _groceryRepoItems.SaveChanges();
                }
            }
        }
예제 #28
0
 public MarksController(GroceryContext context)
 {
     _context = context;
 }
 public GroceryItemsController(GroceryContext context)
 {
     _context = context;
 }
예제 #30
0
 public IndexModel(GroceryContext context)
 {
     _context = context;
 }