public ActionResult Create([Bind("ReviewerName,Score,Text,RestaurantId")] Review review)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(review));
                }

                Lib.Restaurant libRestaurant = Repo.GetRestaurantById(review.RestaurantId);
                var            libReview     = new Lib.Review
                {
                    ReviewerName = review.ReviewerName,
                    Score        = review.Score,
                    Text         = review.Text
                };
                Repo.AddReview(libReview, libRestaurant);
                Repo.Save();

                return(RedirectToAction(nameof(RestaurantController.Details),
                                        "Restaurant", new { id = review.RestaurantId }));
            }
            catch
            {
                return(View(review));
            }
        }
예제 #2
0
        // GET: Restaurant/Delete/5
        public ActionResult Delete(int id)
        {
            Lib.Restaurant libRest = Repo.GetRestaurantById(id);
            var            webRest = new Restaurant
            {
                Id   = libRest.Id,
                Name = libRest.Name
            };

            return(View(webRest));
        }
예제 #3
0
        // GET: Restaurant/Edit/5
        public ActionResult Edit(int id)
        {
            // we pass the current values into the Edit view
            // so that the input fields can be pre-populated instead of blank
            // (important for good UX)
            Lib.Restaurant libRest = Repo.GetRestaurantById(id);
            var            webRest = new Restaurant
            {
                Id   = libRest.Id,
                Name = libRest.Name
            };

            return(View(webRest));
        }
        public ActionResult Create(RestaurantReviews.Library.Restaurant rest)
        {
            //try
            {
                // TODO: Add insert logic here
                RestaurantReviews.Library.MethodCalls.AddRestaurantToDb(rest);
                return(RedirectToAction("All"));
            }

            /*catch
             * {
             *  return View();
             * }*/
        }
예제 #5
0
        // GET: Restaurant/Details/5
        public ActionResult Details(int id)
        {
            Lib.Restaurant libRest = Repo.GetRestaurantById(id);
            var            webRest = new Restaurant
            {
                Id      = libRest.Id,
                Name    = libRest.Name,
                Reviews = libRest.Reviews.Select(y => new Review
                {
                    Id           = y.Id,
                    ReviewerName = y.ReviewerName,
                    Score        = y.Score,
                    Text         = y.Text
                }),
                Score = libRest.Score
            };

            return(View(webRest));
        }
예제 #6
0
        // without [Bind("Name")], this would look in the request body, or query string
        // for the restaurant.Id and for restaurant.Reviews
        // this way, it will only try to bind restaurant.Name, and will leave other properties
        // at default.
        // this is really more of a security thing, because your rendered views should only
        // be sending what you expect
        public ActionResult Edit([FromRoute] int id, [Bind("Name")] Restaurant restaurant)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Lib.Restaurant libRest = Repo.GetRestaurantById(id);
                    libRest.Name = restaurant.Name;
                    Repo.UpdateRestaurant(libRest);
                    Repo.Save();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(restaurant));
            }
            catch (Exception)
            {
                return(View(restaurant));
            }
        }