public IActionResult Add(AddIngredientsViewModel addIngredientsViewModel)
        {
            if (ModelState.IsValid)
            {
                var group = _context.Groups.Find(addIngredientsViewModel.FoodGroupId);
                var unit  = _context.Units.Find(addIngredientsViewModel.UnitId);

                Ingredients newIngredients = new Ingredients
                {
                    User           = _userManager.GetUserAsync(User).Result,
                    Name           = addIngredientsViewModel.Name,
                    Groups         = group,
                    Weight         = addIngredientsViewModel.Weight,
                    ExpirationDate = addIngredientsViewModel.ExpirationDate,
                    Units          = unit
                };

                _context.Ingredients.Add(newIngredients);
                _context.SaveChanges();

                return(Redirect("/Ingredients"));
            }

            return(View(addIngredientsViewModel));
        }
        public IActionResult Add()
        {
            AddIngredientsViewModel addIngredientsViewModel = new AddIngredientsViewModel(_context.Groups.ToList(), _context.Units.ToList());

            return(View(addIngredientsViewModel));
        }
Example #3
0
 public AddIngredientsView(tblRecipe recipe)
 {
     DataContext = new AddIngredientsViewModel(this, recipe);
     InitializeComponent();
 }