Example #1
0
        //GET Action
        public ActionResult Edit(int?id)
        {
            Restaurant restaurant;

            if (!id.HasValue)
            {
                restaurant = new Restaurant();
            }
            else
            {
                RestaurantsRepositories repository = new RestaurantsRepositories();
                restaurant = repository.GetById(id.Value);
                if (restaurant == null)
                {
                    return(RedirectToAction("Index"));
                }
            }
            RestaurantAddEditViewModel model = new RestaurantAddEditViewModel();

            model.Id        = restaurant.Id;
            model.Name      = restaurant.Name;
            model.Address   = restaurant.Address;
            model.Email     = restaurant.Email;
            model.Phone     = restaurant.Phone;
            model.OpenHour  = restaurant.OpenHour;
            model.CloseHour = restaurant.CloseHour;
            return(View(model));
        }
Example #2
0
        // GET: Restaurants
        public ActionResult Index()
        {
            RestaurantsRepositories repository = new RestaurantsRepositories();
            RestaurantListViewModel model      = new RestaurantListViewModel();

            model.Restaurants = repository.GetAll().ToList();
            return(View(model));
        }
Example #3
0
        public ActionResult Edit()
        {
            Restaurant model = new Restaurant();

            TryUpdateModel(model);
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            RestaurantsRepositories repository = new RestaurantsRepositories();

            repository.Save(model);
            return(RedirectToAction("Index"));
        }
Example #4
0
        public ActionResult Delete(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }
            RestaurantsRepositories repo = new RestaurantsRepositories();
            Restaurant model             = new Restaurant();

            model = repo.GetById(id.Value);
            if (model == null || model.IsDeleted)
            {
                return(RedirectToAction("Index"));
            }
            repo.Delete(model);
            return(RedirectToAction("Index"));
        }