Пример #1
0
 public IActionResult Dishprocessor(Dish newdish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(newdish);
         dbContext.SaveChanges();
         return(RedirectToAction("Dishes"));
     }
     return(RedirectToAction("Adddish"));
 }
 public IActionResult CreateDish(Dish newDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(newDish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("New"));
 }
Пример #3
0
 public IActionResult AddDish(Dish NewDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(NewDish);
         dbContext.SaveChanges();
         return(RedirectToAction("index"));
     }
     else
     {
         return(View("NewForm"));
     }
 }
 public IActionResult New(Dish NewDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Dishes.Add(NewDish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View());
     }
 }
Пример #5
0
 public IActionResult CreateDish(Dish fromForm)
 {
     if (ModelState.IsValid)
     {
         _context.Add(fromForm);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("DishForm"));
     }
 }
Пример #6
0
 public IActionResult AddDish(Dishes dish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(dish);
         dbContext.SaveChanges();
         return(RedirectToAction("index"));
     }
     else
     {
         // Oh no!  We need to return a ViewResponse to preserve the ModelState, and the errors it now contains!
         return(View("Create"));
     }
 }
Пример #7
0
 public IActionResult AddDish(Dish newDish)
 {
     if (ModelState.IsValid)
     {
         Console.WriteLine($"***********************{newDish.Chef} | {newDish.Name} | {newDish.Calories} | {newDish.Tastiness} | {newDish.Description}***********************");
         dbContext.Add(newDish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("new"));
     }
 }
Пример #8
0
 private void AddOrder(Dish dish)
 {
     _context.OrderedDish.Add(new OrderedDish()
     {
         DishId = dish.Id
     });
     _context.SaveChanges();
 }
Пример #9
0
        public IActionResult Create(Dish dish)
        {
            if (ModelState.IsValid)
            {
                if (dbContext.Dishes.Any(d => d.Name == dish.Name && d.Chef == dish.Chef))
                {
                    ModelState.AddModelError("Dish", $"{dish.Chef}'s {dish.Name} is already in the system");
                    ViewBag.Dishes = dbContext.Dishes.Reverse().Take(10);
                    return(View("New"));
                }
                dbContext.Dishes.Add(dish);
                dbContext.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View("New"));
        }
Пример #10
0
        public OrderPageAllDishController(DishContext context)
        {
            _context = context;

            if (_context.Dish.Count() == 0)
            {
                _context.Dish.Add(new Dish {
                    IsComplete = false, Name = "SchabowySpokoLux", Desc = "Calkiem spoko"
                });
                _context.SaveChanges();
            }
        }
Пример #11
0
 public IActionResult Create(Dish newDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(newDish);
         dbContext.SaveChanges();
         return(Redirect("/"));
     }
     else
     {
         return(View("NewDish"));
     }
 }
Пример #12
0
 public IActionResult AddDish(Dish dish)
 {
     if (ModelState.IsValid)
     {
         Dish newdish = dish;
         dbContext.Add(newdish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         Console.WriteLine("NOT VALID**************", ModelState.Keys);
         foreach (var error in ModelState)
         {
             if (error.Value.Errors.Count > 0)
             {
                 Console.WriteLine("err msg " + error.Value.Errors[0].ErrorMessage);
             }
         }
         return(RedirectToAction("Add"));
     }
 }
Пример #13
0
        public IActionResult Create(DishViewModel dish)
        {
            if (!ModelState.IsValid)
            {
                return(View("New"));
            }

            Dish newDish = new Dish
            {
                DishName    = dish.DishName,
                Chef        = dish.Chef,
                Tastiness   = dish.Tastiness,
                Calories    = dish.Calories,
                Description = dish.Description,
                CreatedAt   = DateTime.Now,
                UpdatedAt   = DateTime.Now
            };

            _context.Add(newDish);
            _context.SaveChanges();
            Console.WriteLine("######################################################ADEDD##########################");
            return(RedirectToAction("Index"));
        }
Пример #14
0
 public void Save()
 {
     db.SaveChanges();
 }
Пример #15
0
 public IActionResult AddDish(Dish NewDish)
 {
     dbContext.Add(NewDish);
     dbContext.SaveChanges();
     return(RedirectToAction("Index"));
 }