Esempio n. 1
0
        public IActionResult UpdateIngredient(int id)
        {
            var a = _context.Ingredient.AsNoTracking()
                    .Where(k => k.IngredientId == id).FirstOrDefault();
            IngredientVm s = new IngredientVm()
            {
                IngredientId   = a.IngredientId,
                IngredientName = a.IngredientName,
            };

            return(View(s));
        }
Esempio n. 2
0
        public IActionResult UpdateIngredient(IngredientVm st)
        {
            var valid = _context.Ingredient.AsNoTracking().
                        Where(t => t.IngredientName == st.IngredientName).FirstOrDefault();

            if (valid != null)
            {
                ViewBag.Validation = "You have already added " + st.IngredientName;
                return(View());
            }
            Ingredient s = new Ingredient()
            {
                IngredientId   = st.IngredientId,
                IngredientName = st.IngredientName,
            };

            _context.Ingredient.Update(s);
            _context.SaveChanges();
            return(RedirectToAction("IngredientList"));
        }
Esempio n. 3
0
        public IActionResult IngredientList(int Page = 1)
        {
            var li = _context.Ingredient.AsNoTracking().ToList();
            var se = new List <IngredientVm>();
            int c  = 1;

            foreach (var item in li)
            {
                IngredientVm s = new IngredientVm()
                {
                    IngredientId   = item.IngredientId,
                    IngredientName = item.IngredientName,
                    Serial         = c,
                };
                se.Add(s);
                c++;
            }
            var list = se.ToPagedList(Page, 5);

            return(View(list));
        }
Esempio n. 4
0
        public IActionResult AddIngredient(IngredientVm a)
        {
            var valid = _context.Ingredient.AsNoTracking().
                        Where(t => t.IngredientName == a.IngredientName).FirstOrDefault();

            if (valid != null)
            {
                ViewBag.Validation = "You have already added " + a.IngredientName;
                return(View());
            }
            Ingredient s = new Ingredient()
            {
                IngredientId   = a.IngredientId,
                IngredientName = a.IngredientName,
            };

            _context.Ingredient.Add(s);
            _context.SaveChanges();
            ModelState.Clear();
            ViewBag.Success = "You have succesfully added " + a.IngredientName;
            return(View());
        }