public void EditRestaurant(Library.Restaurant restaurant)
 {
     if (_db.Restaurant.Find(restaurant.RestaurantId) != null)
     {
         _db.Restaurant.Update(RestaurantMapper.Map(restaurant));
     }
 }
Пример #2
0
 /// <summary>
 /// Add a review, and optionally associate it with a restaurant.
 /// </summary>
 /// <param name="review">The review</param>
 /// <param name="restaurant">The restaurant (or null if none)</param>
 public void AddReview(Library.Review review, Library.Restaurant restaurant)
 {
     if (restaurant != null)
     {
         // get the db's version of that restaurant
         // (can't use Find with Include)
         var contextRestaurant = _db.Restaurant.Include(r => r.Review).First(r => r.Id == restaurant.Id);
         restaurant.Reviews.Add(review);
         contextRestaurant.Review.Add(Mapper.Map(review));
     }
     else
     {
         _db.Add(Mapper.Map(review));
     }
 }
 public void AddRestaurant(Library.Restaurant restaurant)
 {
     _db.Restaurant.Add(RestaurantMapper.Map(restaurant));
 }
Пример #4
0
 /// <summary>
 /// Update a restaurant. Will not process any changes to its reviews.
 /// </summary>
 /// <param name="restaurant">The restaurant with changed values</param>
 public void UpdateRestaurant(Library.Restaurant restaurant)
 {
     // calling Update would mark every property as Modified.
     // this way will only mark the changed properties as Modified.
     _db.Entry(_db.Restaurant.Find(restaurant.Id)).CurrentValues.SetValues(Mapper.Map(restaurant));
 }
Пример #5
0
 public static Restaurant Map(Library.Restaurant restaurant) => new Restaurant
 {
     Id     = restaurant.Id,
     Name   = restaurant.Name,
     Review = Map(restaurant.Reviews).ToList()
 };