Esempio n. 1
0
 public ActionResult AddHotDog(HotDog hotDog)
 {
     if (ModelState.IsValid)
     {
         if (hotDog.Id == 0)
         {
             _db.HotDog.Add(hotDog);
             _db.SaveChanges();
         }
         else
         {
             var hotDogToUpdate = _db.HotDog.Single(x => x.Id == hotDog.Id);
             hotDogToUpdate.Name  = hotDog.Name;
             hotDogToUpdate.Phone = hotDog.Phone;
             _db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     else
     {
         var sauces = _db.Sauces.ToList();
         HotDogWithSauceViewModel hotDogWithSauceViewModel = new HotDogWithSauceViewModel()
         {
             HotDog = hotDog,
             Sauces = sauces
         };
         return(View("HotDogForm", hotDogWithSauceViewModel));
     }
 }
Esempio n. 2
0
        public ActionResult CreateHotDog()
        {
            var sauces = _db.Sauces.ToList();
            HotDogWithSauceViewModel hotDogWithSauceViewModel = new HotDogWithSauceViewModel()
            {
                Sauces = sauces,
                HotDog = new HotDog()
            };

            return(View("HotDogForm", hotDogWithSauceViewModel));
        }
Esempio n. 3
0
        public ActionResult EditHotDog(int id)
        {
            var hotDog = _db.HotDog.SingleOrDefault(x => x.Id == id);

            if (hotDog == null)
            {
                return(HttpNotFound());
            }

            HotDogWithSauceViewModel hotDogWithSauceViewModel = new HotDogWithSauceViewModel()
            {
                Sauces = _db.Sauces.ToList(),
                HotDog = hotDog
            };

            return(View("HotDogForm", hotDogWithSauceViewModel));
        }