Пример #1
0
 public ActionResult CreateRestaurant(Resto restaurant)
 {
     if (ModelState.IsValid)
     {
         using (IDal dal = new Dal())
         {
             if (!dal.RestaurantExiste(restaurant.Nom))
             {
                 dal.CreerRestaurant(restaurant.Nom, restaurant.Telephone);
                 return RedirectToAction("Index");
             }
             else
             {
                 //ViewBag.MessageErreur = "Ce restaurant existe deja !";
                 ModelState.AddModelError("Nom", "Un restaurant existe deja avec ce nom la !");
                 return View();
             }
         }
     }
     else
     {
         ViewBag.MessageErreur = "Valeurs incorrects !";
         return View();
     }
 }
Пример #2
0
 // GET: Restaurant
 public ActionResult Index()
 {
     using (IDal dal = new Dal())
     {
         var restos = dal.ObtientTousLesRestaurants();
         return View(restos);
     }
 }
Пример #3
0
 public ActionResult ModifierRestaurant(Resto resto)
 {
     if (!ModelState.IsValid)
     {
         return View(resto);
     }
     using (IDal dal = new Dal())
     {
         dal.ModifierRestaurant(resto.Id, resto.Nom, resto.Telephone);
         return RedirectToAction("Index");
     }
 }
Пример #4
0
 public ActionResult ModifierRestaurant(int? id)
 {
     if (id.HasValue)
     {
         using (IDal dal = new Dal())
         {
             Resto restaurant = dal.ObtientTousLesRestaurants().FirstOrDefault(r => r.Id == id.Value);
             if (restaurant == null)
                 return View("Error");
             return View(restaurant);
         }
     }
     else
         return View("Error");
 }
Пример #5
0
        public void ModifierRestaurant_CreerPuisModifier()
        {
            IDal dal;
            using (dal = new Dal())
            {
                dal.CreerRestaurant("Chez mamie", "04 75 46 22 14");
                List<Resto> restos = dal.ObtientTousLesRestaurants();
                int id = restos.First(r => r.Nom == "Chez mamie").Id;

                dal.ModifierRestaurant(id, "Chez Mamie", null);

                restos = dal.ObtientTousLesRestaurants();
                Assert.IsNotNull(restos);
                Assert.AreEqual(1, restos.Count);
                Assert.AreEqual("Chez Mamie", restos[0].Nom);
                Assert.IsNull(restos[0].Telephone);
            }
        }
Пример #6
0
        public void CreerNouveauRestau_ObtenirNouveauRestau()
        {
            // On creer un objet provenant de l'interface
            IDal dal;
            using (dal = new Dal())
            {
                dal.CreerRestaurant("Ici c'est bon", "06 10 20 30 40");
                List<Resto> restos = dal.ObtientTousLesRestaurants();

                Assert.IsNotNull(restos);
                Assert.AreEqual(1, restos.Count);
                Assert.AreEqual("Ici c'est bon", restos[0].Nom);
                Assert.AreEqual("06 10 20 30 40", restos[0].Telephone);
            }
        }