Example #1
0
      // GET: Items/Create
      public IActionResult Create(string type)
      {
          TempData.Remove("missing");
          TempData.Remove("LowQty");
          ViewData["User"]       = new SelectList(_context.AspNetUsers, "Id", "Id");
          TempData["IngredType"] = type;

          //Build a list of all possible ingredients matching the selected type
          List <IngredientType> ingredientType = _context.IngredientTypes.Where(x => x.IngCategory == type).ToList();

          //Build a list of all inventory items specific to the current logged in user
          List <Item> userItems = _context.Items.Where(u => u.User == User.FindFirst(ClaimTypes.NameIdentifier).Value).ToList();

          //Build a list of ingredients that are a comparison of selected type combined with current user
          //Meaning this list will be of the selected type which are not in logged in user's current inventory
          List <Ingredient> ingredients = _ingredient.GetAllIngredients().Where(x => !userItems.Any(y => y.ItemName == x.strIngredient1) && ingredientType.Any(z => z.ApistrIngredient == x.strIngredient1)).ToList();

          //Send the ingredients list as a dropdown selector to the view via ViewBag
          ViewBag.Ingredients = new SelectList(ingredients, "strIngredient1", "strIngredient1");
          return(View());
      }