public static Restaurant Create(this RestaurantsEntities DB, Restaurant restaurant)
        {
            Restaurant newRestaurant = DB.Restaurants.Add(restaurant);

            DB.SaveChanges();
            return(newRestaurant);
        }
        public static Rating Create(this RestaurantsEntities DB, Rating rating)
        {
            Rating newRating = DB.Ratings.Add(rating);

            DB.UpdateRating(newRating.Restaurant_Id);
            DB.SaveChanges();
            return(newRating);
        }
        public static void DeleteRestaurant(this RestaurantsEntities DB, int restaurantId)
        {
            Restaurant restaurantToDelete = DB.Restaurants.Find(restaurantId);

            if (restaurantToDelete != null)
            {
                // Cascade ratings delete
                DB.Restaurants.Remove(restaurantToDelete);
                DB.SaveChanges();
            }
        }
        public static void DeleteRating(this RestaurantsEntities DB, int ratingId)
        {
            Rating ratingToDelete = DB.Ratings.Find(ratingId);

            if (ratingToDelete != null)
            {
                int restaurantToUpdateId = ratingToDelete.Restaurant_Id;
                DB.Ratings.Remove(ratingToDelete);
                DB.UpdateRating(restaurantToUpdateId);
                DB.SaveChanges();
            }
        }
        public static Restaurant Update(this RestaurantsEntities DB, Restaurant restaurant)
        {
            if (restaurant != null)
            {
                Restaurant restaurantToUpdate = DB.Restaurants.Find(restaurant.Id);
                if (restaurantToUpdate != null)
                {
                    restaurantToUpdate.Update(restaurant);

                    DB.Entry(restaurantToUpdate).State = System.Data.Entity.EntityState.Modified;
                    DB.SaveChanges();
                    return(restaurantToUpdate);
                }
            }
            return(null);
        }
 public static Rating Update(this RestaurantsEntities DB, Rating rating)
 {
     if (rating != null)
     {
         Rating ratingToUpdate = DB.Ratings.Find(rating.Id);
         if (ratingToUpdate != null)
         {
             ratingToUpdate.Update(rating);
             DB.Entry(ratingToUpdate).State = System.Data.Entity.EntityState.Modified;
             DB.UpdateRating(ratingToUpdate.Restaurant_Id);
             DB.SaveChanges();
             return(ratingToUpdate);
         }
     }
     return(null);
 }