public IActionResult Create(RestaurantEditModel model)
        {
            if (ModelState.IsValid)
            {
                var newRestaurant = new Restaurant();
                newRestaurant.Name    = model.Name;
                newRestaurant.Cuisine = model.Cuisine;

                newRestaurant = _restaurantData.Add(newRestaurant);

                //return ViewModels("Details", newRestaurant);
                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                return(View());
            }
        }
Beispiel #2
0
        public IActionResult Create(RestaurantEditModel model)
        {
            if (ModelState.IsValid)
            {
                var newRestaurant = new Restaurant();
                newRestaurant.Name    = model.Name;
                newRestaurant.Cuisine = model.Cuisine;

                newRestaurant = _restaurantData.Add(newRestaurant);

                // this empty object that gets returned will go into the url
                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                return(View());
            }
        }
Beispiel #3
0
        public IActionResult Create(RestaurantEditModel model)
        {
            if (ModelState.IsValid)
            {
                var newRestaurant = new Restaurant()
                {
                    Name    = model.Name,
                    Cuisine = model.Cuisine
                };

                newRestaurant = _restaurantData.Add(newRestaurant);
                return(RedirectToAction("Details", new { id = newRestaurant.Id }));
            }
            else
            {
                return(View(model));
            }
        }
        public IActionResult Create(RestaurantEditModel model)
        {
            if (ModelState.IsValid)
            {
                var newRestaurant = new Restaurant();
                newRestaurant.Name        = model.Name;
                newRestaurant.Description = model.Description;
                newRestaurant.Cuisine     = model.Cuisine;
                newRestaurant.UserId      = User.FindFirst(ClaimTypes.NameIdentifier).Value;

                newRestaurant = _restaurantData.Add(newRestaurant);

                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                return(View());
            }
        }
Beispiel #5
0
        public IActionResult Create(RestaurantEditModel restaurantEditModel)
        {
            if (ModelState.IsValid)
            {
                var newRestaurant = new Restaurant()
                {
                    Name        = restaurantEditModel.Name,
                    CuisineType = restaurantEditModel.CuisineType
                };

                _restaurantData.Add(newRestaurant);

                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                return(View());
            }
        }
Beispiel #6
0
        public IActionResult Create(RestaurantEditModel model)
        {
            if (ModelState.IsValid)
            {
                var restaurant = new Restaurant
                {
                    Name    = model.Name,
                    Cuisine = model.Cuisine
                };

                var details = _restaurantData.Add(restaurant);

                return(RedirectToAction(nameof(Details), new { id = restaurant.Id }));
            }
            else
            {
                return(View());
            }
        }
Beispiel #7
0
        public IActionResult Create(RestaurantEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var resto = new Restaurant()
            {
                Name     = model.Name,
                Couisine = model.Couisine
            };

            resto = _restotantData.Add(resto);
            return(RedirectToAction(nameof(Details), new { id = resto.Id }));

            //return View("Details",resto);
            //This way return a new view in every Http request
        }
Beispiel #8
0
        public IActionResult Create(RestaurantEditModel model)
        {
            //if (ModelState.IsValid)
            //{
            //    var newRestaurant = new Restaurant
            //    {
            //        Name = model.Name,
            //        Cuisine = model.Cuisine
            //    };

            //    newRestaurant = _restaurantData.Add(newRestaurant);

            //    return RedirectToAction(nameof(Details), new { id = newRestaurant.Id });
            //}
            //else
            //{
            //    return View();
            //}
            return(null);
        }
        [ValidateAntiForgeryToken] // <<< Important
        public IActionResult Create(RestaurantEditModel model)
        {
            if (this.ModelState.IsValid)
            {
                var newRestaurant = new Restaurant()
                {
                    Name    = model.Name,
                    Cuisine = model.Cuisine
                };
                newRestaurant = _restaurantData.Add(newRestaurant);

                // RedirectToAction instead of simply returning a View() we force
                // an HTTP GET after the HTTP post, to avoid a user refresh on the post
                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                return(View()); // Display validation error
            }
        }
Beispiel #10
0
        public IActionResult Create(RestaurantEditModel model)
        {
            //this property is false if the user did not fill out all the required properties on the model. In our
            //case, the user has to enter in a restaurant name because of the Required attribute on the model.
            if (ModelState.IsValid)
            {
                var newRes = new Restaurant();
                newRes.Name    = model.Name;
                newRes.Cuisine = model.Cuisine;

                newRes = _restaurantData.Add(newRes);

                return(RedirectToAction(nameof(Details), new { id = newRes.Id }));
            }
            //the model state is invalid. Return the view again and make them retry
            else
            {
                return(View());
            }
        }
Beispiel #11
0
        public IActionResult Create(RestaurantEditModel model)
        {
            //ModelState.IsValid we check if is properly populated based on the data notation
            if (ModelState.IsValid)
            {
                var newRestaurant = new Restaurant
                {
                    Name    = model.Name,
                    Cuisine = model.Cuisine
                };

                newRestaurant = _restaurantData.Add(newRestaurant);

                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                return(View());
            }
        }
Beispiel #12
0
        public void HiddenProperty_should_resolve_to_top_most_member()
        {
            var restaurantEditModel = new RestaurantEditModel {
                Cuisine = CuisineType.Italian, Name = "Test name"
            };
            var restaurantModel = new Restaurant {
                Cuisine = CuisineType.Italian, Name = "Test name"
            };

            var restaurantList = new RestaurantList {
                Restaurants = new[] { restaurantModel }
            };
            var editRestaurantList = new RestaurantEditList {
                Restaurants = new[] { restaurantEditModel }
            };

            MapTester.ForMap <RestaurantList, RestaurantEditList>()
            // ignored since the internal constructor of MapTester is what's being tested
            .IgnoringMember(dest => dest.Restaurants)
            .AssertMappedValues(restaurantList, editRestaurantList);
        }
Beispiel #13
0
        public IActionResult RestaurantEdit(int id, RestaurantEditModel restaurant)
        {
            if (!ModelState.IsValid || id <= 0)
            {
                return(View(nameof(RestaurantEdit), restaurant));
            }

            var res = new Restaurant()
            {
                Address = restaurant.Address,
                Cuisine = restaurant.CuisineType,
                Name    = restaurant.Name
            };

            if (_restaurantManager.EditRestaurant(id, res))
            {
                return(RedirectToAction("Details", new { id = id }));
            }

            return(View(nameof(RestaurantEdit), restaurant));
        }
Beispiel #14
0
        [ValidateAntiForgeryToken] //Add this to POST request in order
        //this is implemented with hidden input in order to make sure that the form that users is sending to us
        //was created by us
        public IActionResult Create(RestaurantEditModel model)
        {
            if (ModelState.IsValid)
            {
                var newRestaurant = new Restaurant();
                newRestaurant.Name   = model.Name;
                newRestaurant.Cusine = model.Cusine;

                newRestaurant = restaurantData.Add(newRestaurant);

                // this way if users refresh browser it will post same request again
                //return View("Details", newRestaurant);

                //TO FIX we need to use
                //POST Redirect GET Pattern and force uses to send get request, this way user will be able to refresh new page without resending data
                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                return(View());
            }
        }
Beispiel #15
0
        //asp takes the posted data and tries to create this parameter model
        public IActionResult Create(RestaurantEditModel model)
        {
            if (ModelState.IsValid)
            {
                var newRestaurant = new Restaurant();
                newRestaurant.Name    = model.Name;
                newRestaurant.Cuisine = model.Cuisine;

                newRestaurant = _restaurantData.Add(newRestaurant);

                //return View("Details", newRestaurant);
                //redirect so they can't keep posting if they refresh.
                //extra anonomous variable not part of routing will become url get params.
                //return RedirectToAction(nameof(Details), new { id = newRestaurant.Id, foo="bar"});
                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                //return RedirectToAction(nameof(Create));
                return(View());
            }
        }
        public IActionResult Create(RestaurantEditModel model)
        {
            if (ModelState.IsValid)
            {
                Restaurant newRestaurant = new Restaurant
                {
                    Name    = model.Name,
                    Cuisine = model.Cuisine
                };

                newRestaurant = _restaurantData.Add(newRestaurant);

                //return View("Details", newRestaurant);
                // fix the form resubmit
                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                // Error messages based on ModelState
                return(View());
            }
        }
        [ValidateAntiForgeryToken]         // always have this on posts for webapps
        public IActionResult Create(RestaurantEditModel model)
        {
            // always check if IsValid
            if (ModelState.IsValid)
            {
                // mapp form data to the new restaurant
                var newRestaurant = new Restaurant();
                newRestaurant.Name    = model.Name;
                newRestaurant.Cuisine = model.Cuisine;

                newRestaurant = _restaurantData.Add(newRestaurant);

                // Post-Redirect-Get pattern
                // without this approach, the user could refresh the page and repost.
                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));
            }
            else
            {
                // try to create again
                return(View());
            }
        }
        public IActionResult Create(RestaurantEditModel model /* input model! */)
        {
            if (ModelState.IsValid)             //ModelState datastruct produced by MVC behind scenes, on rcv'g input model!
            {
                var newRestaurant = new Restaurant()
                {
                    Name    = model.Name,
                    Cuisine = model.Cuisine
                };
                newRestaurant = _restaurantData.Add(newRestaurant);

                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id }));                   // POST-REDIRECT-GET::STEP2/3 -> Redirect to ACTION 'Details'
            }
            else
            {
                return(View());                 // if model NOT valid;
                // re-present the view again 2 user! FOR valid re-Input
                //								& to correct their INFO
                // + NOTE: tagHelpers are going to work w/ ModelState
            }
            //return View("Details", newRestaurant);
            //return Content("POST-ed");
        }
        [ValidateAntiForgeryToken]  // This needs validate Crosssite Forgery validation
        public IActionResult Create(RestaurantEditModel model)
        {
            // It calls model binding here
            // Also gete model state here
            if (ModelState.IsValid)
            {
                // Creates a new Restaurant
                var newRestaurant = new Restaurant();
                newRestaurant.Name    = model.Name;
                newRestaurant.Cuisine = model.Cuisine;

                newRestaurant = _restaurantaData.Add(newRestaurant);

                // return View("Details", newRestaurant); // This sends the page immadiately..It should be redirected..
                return(RedirectToAction(nameof(Details), new { id = newRestaurant.Id, foo = "bar" })); // redirects to Home/Details/Id .. foo=bar is in QueryString
            }
            else
            {
                return(View()); // Displays the the page that was submitted but didn't pass validation and displays erro meesages in the page ...
                // Look at the Create.cshtml   <span asp-validation-for="Name"></span>
            }
            // return Content("POST");
        }
Beispiel #20
0
        private static long CreateRestaurant(RestaurantEditModel model)
        {
            using (var db = new DataContext())
            {
                var r = new Restaurant
                            {
                                Name = model.Name,
                                Email = model.Email,
                               // Company = db.Companies.Find(model.Company.Id),
                                Url = model.Url,
                                Description = model.Description,
                                Information = model.Information,
                               // Area = model. db.LunchAreas.Find(model.CityId),
                                Adress =
                                    new Adress
                                        {
                                            PostCode = model.Adress.PostCode,
                                            Street = model.Adress.Street,

                                        }
                            };
                db.Restaurants.Add(r);
                db.SaveChanges();
                return r.Id;
            }
        }