Ejemplo n.º 1
0
        public ActionResult RestaurantDelete(int id)
        {
            restaurant      r  = models.restaurants.FirstOrDefault(x => x.restaurant_id == id);
            city_restaurant cr = models.city_restaurant.FirstOrDefault(x => x.restaurant_id == id);

            models.city_restaurant.Remove(cr);
            models.restaurants.Remove(r);
            models.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult RestaurantAdd(restaurant r, city c, HttpPostedFileBase file)
        {
            city_restaurant cityRestaurant = new city_restaurant();

            if (file != null && file.ContentLength > 0)
            {
                string fileName = Path.Combine(Server.MapPath("~/Content/assets_1/img/"), Path.GetFileName(file.FileName));
                file.SaveAs(fileName);
                string filePath = "/Content/assets_1/img/" + file.FileName;
                r.image   = filePath;
                r.role_id = 2;
                cityRestaurant.city_id       = c.city_id;
                cityRestaurant.restaurant_id = r.restaurant_id;
                models.city_restaurant.Add(cityRestaurant);
                models.restaurants.Add(r);
                models.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.message = "Try again";
                return(View("RestaurantAdd"));
            }
        }