public IActionResult Index() { Restaurant model = new Restaurant() { Id = 1, Name = "Sabatino's" }; return View(model); }
//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; }
public ActionResult Edit(Restaurant restaurant) { if (ModelState.IsValid) { db.Entry(restaurant).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(restaurant); }
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() }; }
public ActionResult Create(Restaurant restaurant) { if (ModelState.IsValid) { db.Restaurants.Add(restaurant); db.SaveChanges(); return RedirectToAction("Index"); } return View(restaurant); }
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); }
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; }
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); }
public ActionResult Create(Restaurant newRestaurant) { try { using (_db) { _db.Restaurants.Add(newRestaurant); _db.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
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; }
private static double GetAverageRating(Restaurant restaurant) { return restaurant.Reviews.Any() ? restaurant.Reviews.Average(review => review.Rating) : 0; }
private static RatingRestult ComputeRating(Restaurant data) { var target = new RestaurantRater(data); var result = target.ComputeRating(); return result; }