示例#1
0
 public IActionResult Index()
 {
     Restaurant model = new Restaurant() {
         Id = 1,
         Name = "Sabatino's"
     };
     return View(model);
 }
示例#2
0
        //Warning: Below is a HELPER method, not a TEST method
        private Restaurant BuildRestaurantsAndReviews(params int[] ratings)
        {
            var restaurant = new Restaurant();

            restaurant.Reviews =
                ratings.Select(r => new RestaurantReview() {Rating = r})
                    .ToList();
            return restaurant;
        }
示例#3
0
 public ActionResult Edit(Restaurant restaurant)
 {
     if (ModelState.IsValid) {
         db.Entry(restaurant).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(restaurant);
 }
示例#4
0
 private static RestaurantListViewModel MapRestaurantToViewModel(Restaurant restaurant)
 {
     return new RestaurantListViewModel {
                                            Id = restaurant.Id,
                                            Name = restaurant.Name,
                                            City = restaurant.City,
                                            Country = restaurant.Country,
                                            CountOfReviews = restaurant.Reviews.Count()
                                        };
 }
示例#5
0
        public ActionResult Create(Restaurant restaurant)
        {
            if (ModelState.IsValid) {
                db.Restaurants.Add(restaurant);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(restaurant);
        }
示例#6
0
 private static Restaurant CreateRestaurantWithReveiewRatings(params int[] reviewRatings)
 {
     var data = new Restaurant();
     foreach (var reviewRating in reviewRatings) {
         data.Reviews.Add(new RestaurantReview {
                                                   Rating = reviewRating
                                               });
     }
     return data;
 }
 public ActionResult Edit(Restaurant restaurant)
 {
     if (ModelState.IsValid)
     {
         _db.Update(restaurant);
         _db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(restaurant);
 }
        public void Computes_Result_For_One_Review()
        {
            var data = new Restaurant();
            data.Reviews = new List<RestaurantReview>();
            data.Reviews.Add(new RestaurantReview() { Rating = 4 });

            var rater = new RestaurantRater(data);
            var result = rater.ComputeResult(new SimpleRatingAlgorithm(),10);

            Assert.AreEqual(4, result.Rating);
        }
示例#9
0
文件: RatingTests.cs 项目: qThorn/App
        private Restaurant BuildRestaurantAndReviews(params int[] ratings)
        {
            var restaurant = new Restaurant();

            // need a using statement for System.Linq at the top of the file
            restaurant.Reviews =
                ratings.Select(r => new RestaurantReview { Rating = r })
                       .ToList();

            return restaurant;
        }
示例#10
0
        public ActionResult Edit(Restaurant restaurant)
        {
            if (ModelState.IsValid)
            {

                _db.Entry(restaurant).State = EntityState.Modified;
                _db.SaveChanges();
                return RedirectToAction("Details", new { id = restaurant.ID });

            }
            restaurant = _db.Restaurants.Find(restaurant.ID);
            return View(restaurant);
        }
示例#11
0
 public ActionResult Create(Restaurant newRestaurant)
 {
     try
     {
         using (_db)
         {
             _db.Restaurants.Add(newRestaurant);
             _db.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
示例#12
0
        public ActionResult Create(Restaurant restaurant)
        {
            //if (Request.Files["files"] != null)
            //{
            //    byte[] Image;
            //    using (var binaryReader = new BinaryReader(Request.Files["files"].InputStream))
            //    {
            //        Image = binaryReader.ReadBytes(Request.Files["files"].ContentLength);
            //    }
            //    restaurant.Photo = Image;
            //}

            //_db.Restaurants.Add(restaurant);
            _db.SaveChanges();
            return RedirectToAction("Index");
        }
 public RestaurantRater(Restaurant restaurant)
 {
     
     this._restaurant = restaurant;
 }
示例#14
0
 private static double GetAverageRating(Restaurant restaurant)
 {
     return restaurant.Reviews.Any() ? restaurant.Reviews.Average(review => review.Rating) : 0;
 }
示例#15
0
 private static RatingRestult ComputeRating(Restaurant data)
 {
     var target = new RestaurantRater(data);
     var result = target.ComputeRating();
     return result;
 }