예제 #1
0
        public static Restaurant Create(this RestaurantsEntities DB, Restaurant restaurant)
        {
            Restaurant newRestaurant = DB.Restaurants.Add(restaurant);

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

            DB.UpdateRating(newRating.Restaurant_Id);
            DB.SaveChanges();
            return(newRating);
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        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();
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
 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);
 }