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 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 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);
 }