Esempio n. 1
0
        //[ValidateAntiForgeryToken]
        public IActionResult Create(ResturantEditModel resturantEdit)
        {
            if (ModelState.IsValid)
            {
                Resturant newRresturant = new Resturant();
                newRresturant.Name       = resturantEdit.Name;
                newRresturant.CusineType = resturantEdit.CusineType;
                newRresturant.Address    = resturantEdit.Address;

                var a = _resturant.Add(newRresturant);

                //return View("Details", a);

                ////when user decides to refresh the returned view,
                //the req. rendered will execute a http post req again to the application
                //causing redundant data to be saved again.
                //inorder to solve the above mentioned
                //issue we'll return a redirect action insted of a view.
                return(RedirectToAction(nameof(Details), new { a.Id, status = "success" }));
            }
            else
            {
                return(View());
            }
        }
Esempio n. 2
0
        public IActionResult Create(ResturantEditModel model)
        {
            if (ModelState.IsValid)
            {
                var newRestaurant = new Restaurant();
                newRestaurant.Name    = model.Name;
                newRestaurant.Cuisine = model.Cuisine;

                newRestaurant = _restaurantData.Add(newRestaurant);

                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                return(View());
            }
        }