Ejemplo n.º 1
0
        public ActionResult List()
        {
            FoodRestaurantContext db = new FoodRestaurantContext();
            List <Restaurant>     restaurantsList = db.Restaurants.ToList();

            return(View(restaurantsList));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id, CreateOrEditRestaurantModel restaurant)
        {
            FoodRestaurantContext db = new FoodRestaurantContext();

            if (!ModelState.IsValid)
            {
                restaurant.Cities = db.Cities.Select(m => new SelectListItem()
                {
                    Text = m.Name, Value = m.Id.ToString()
                }).ToList();
                return(View(restaurant));
            }


            Restaurant restaurantToEdit = db.Restaurants.FirstOrDefault(m => m.Id == id);

            if (restaurantToEdit != null)
            {
                restaurantToEdit.Name   = restaurant.Name;
                restaurantToEdit.CityId = restaurant.CityId;
                db.SaveChanges();
            }

            return(RedirectToAction("List"));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id)
        {
            FoodRestaurantContext db         = new FoodRestaurantContext();
            Restaurant            restaurant = db.Restaurants.FirstOrDefault(m => m.Id == id);

            if (restaurant == null)
            {
                return(RedirectToAction("List"));
            }

            return(View(restaurant));
        }
Ejemplo n.º 4
0
        public ActionResult Delete(int id)
        {
            FoodRestaurantContext db         = new FoodRestaurantContext();
            Restaurant            restaurant = db.Restaurants.FirstOrDefault(m => m.Id == id);

            if (restaurant != null)
            {
                db.Restaurants.Remove(restaurant);
                db.SaveChanges();
            }

            return(RedirectToAction("List"));
        }
Ejemplo n.º 5
0
        public ActionResult Create()
        {
            CreateOrEditRestaurantModel model = new CreateOrEditRestaurantModel();

            FoodRestaurantContext db = new FoodRestaurantContext();

            model.Cities = db.Cities.Select(m => new SelectListItem()
            {
                Text = m.Name, Value = m.Id.ToString()
            }).ToList();

            return(View(model));
        }
Ejemplo n.º 6
0
        public ActionResult Edit(int id, Restaurant restaurant)
        {
            if (!ModelState.IsValid)
            {
                return(View(restaurant));
            }

            FoodRestaurantContext db = new FoodRestaurantContext();
            Restaurant            restaurantToEdit = db.Restaurants.FirstOrDefault(m => m.Id == id);

            if (restaurantToEdit != null)
            {
                restaurantToEdit.Name = restaurant.Name;
                db.SaveChanges();
            }

            return(RedirectToAction("List"));
        }
Ejemplo n.º 7
0
        public ActionResult Create(Restaurant restaurant)
        {
            if (!ModelState.IsValid)
            {
                return(View(restaurant));
            }

            Restaurant restaurantToCreate = new Restaurant();

            restaurantToCreate.Name = restaurant.Name;

            FoodRestaurantContext db = new FoodRestaurantContext();

            db.Restaurants.Add(restaurantToCreate);
            db.SaveChanges();

            return(RedirectToAction("List"));
        }
Ejemplo n.º 8
0
        public ActionResult Edit(int id)
        {
            FoodRestaurantContext db         = new FoodRestaurantContext();
            Restaurant            restaurant = db.Restaurants.FirstOrDefault(m => m.Id == id);

            if (restaurant == null)
            {
                return(RedirectToAction("List"));
            }

            CreateOrEditRestaurantModel model = new CreateOrEditRestaurantModel();

            model.Id     = restaurant.Id;
            model.Name   = restaurant.Name;
            model.CityId = restaurant.CityId;

            model.Cities = db.Cities.Select(m => new SelectListItem()
            {
                Text = m.Name, Value = m.Id.ToString()
            }).ToList();

            return(View(model));
        }
Ejemplo n.º 9
0
        public ActionResult Create(CreateOrEditRestaurantModel restaurant)
        {
            FoodRestaurantContext db = new FoodRestaurantContext();

            if (!ModelState.IsValid)
            {
                restaurant.Cities = db.Cities.Select(m => new SelectListItem()
                {
                    Text = m.Name, Value = m.Id.ToString()
                }).ToList();
                return(View(restaurant));
            }

            Restaurant restaurantToCreate = new Restaurant();

            restaurantToCreate.Name   = restaurant.Name;
            restaurantToCreate.CityId = restaurant.CityId;

            db.Restaurants.Add(restaurantToCreate);
            db.SaveChanges();

            return(RedirectToAction("List"));
        }