Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("RecipeId,UserId,RecipeName,Portions,Instructions,Time,DietType,Ingredients")] Recipes recipe, ICollection <Ingredients> ingredients, string submitButton)
        {
            if (User.Claims.Count() == 0)
            {
                return(View("NotFound"));
            }

            string userId = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value;

            if (ModelState.IsValid)
            {
                recipe.UserId = userId;
                _context.Add(recipe);

                await _context.SaveChangesAsync();

                //bool showBadge = ShowBadgeMessage(recipes.DietType, recipes.UserId);
                //if (showBadge)
                //{ return RedirectToAction("Profile", "Account"); }

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.AlreadyAddedIngredients = ingredients.Reverse().ToList();
            TempData["ingredients"]         = GetIngredientList();
            return(View(recipe));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("UserId")] Users users)
        {
            if (ModelState.IsValid)
            {
                _context.Add(users);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(users));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("IngredientId,RecipeId,IngredientName,AmountG,RecipeUnit")] Ingredients ingredients)
        {
            Recipes recipes = new Recipes();
            string  UserId  = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value;

            if (User.Claims.Count() > 0)
            {
                ViewBag.UserId = UserId;
            }
            if (ModelState.IsValid)
            {
                _context.Add(ingredients);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            string recipe = recipes.RecipeName;

            ViewBag.RecipeName   = recipe;
            ViewData["RecipeId"] = new SelectList(_context.Recipes.Where(r => r.UserId == UserId), "RecipeId", "Instructions", ingredients.RecipeId);
            return(View(ingredients));
            //var recipelist = _context.Recipes.Where(r => r.UserId == UserId);
            //string recipe = recipelist.ToString();
        }