Beispiel #1
0
 public static IEnumerable <Restaurant> FindRestaurantByName(string key)
 {
     using (db = new RestaurantReviewsEntities())
     {
         return(db.Restaurants.Where(x => x.name.Contains(key)).Include("Reviews").ToList());
     }
 }
Beispiel #2
0
 public static IEnumerable <Restaurant> ReadRestaurantsSortByName()
 {
     using (db = new RestaurantReviewsEntities())
     {
         return(db.Restaurants.OrderByDescending(x => x.name).Include("Reviews").ToList());
     }
 }
Beispiel #3
0
 public static IEnumerable <Restaurant> ReadRestaurants()
 {
     using (db = new RestaurantReviewsEntities())
     {
         return(db.Restaurants.Include("Review").ToList());
     }
 }
Beispiel #4
0
 public static IEnumerable <Restaurant> FindRestaurantByID(int id)
 {
     using (db = new RestaurantReviewsEntities())
     {
         yield return(db.Restaurants.Find(id));
     }
 }
Beispiel #5
0
 public static IEnumerable <Restaurant> GetRestaurants()
 {
     using (db = new RestaurantReviewsEntities())
     {
         return(db.Restaurants.ToList());
     }
 }
Beispiel #6
0
 public static IEnumerable <Restaurant> GetTop3Restaurants()
 {
     using (db = new RestaurantReviewsEntities())
     {
         return(db.Restaurants.OrderByDescending(x => x.AvgRating).Take(3).Include("Review").ToList());
     }
 }
Beispiel #7
0
 public static IEnumerable <Restaurant> ReadRestaurantsSortByRating(int count)
 {
     using (db = new RestaurantReviewsEntities())
     {
         return(db.Restaurants.OrderByDescending(x => x.AvgRating).Take(3).Include("Reviews").ToList());
     }
 }
        public static void CreateReview(Review rev)
        {
            using (db = new RestaurantReviewsEntities())
            {
                Logger        log = LogManager.GetCurrentClassLogger();
                StringBuilder msg = new StringBuilder();

                db.Reviews.Add(rev);
            }
        }
        public static void DeleteReviewByID(int id)
        {
            using (db = new RestaurantReviewsEntities())
            {
                Logger        log = LogManager.GetCurrentClassLogger();
                StringBuilder msg = new StringBuilder();

                Review rev = db.Reviews.Find(id);

                db.Reviews.Remove(rev);
            }
        }
        public static void UpdateReview(Review review)
        {
            using (db = new RestaurantReviewsEntities())
            {
                Logger        log = LogManager.GetCurrentClassLogger();
                StringBuilder msg = new StringBuilder();

                Review rev = db.Reviews.Find(review.id);

                rev.rating = review.rating;
                rev.name   = review.name;
                rev.text   = review.text;
            }
        }
        public static void UpdateRestaurant(Restaurant newRestaurant)
        {
            using (db = new RestaurantReviewsEntities())
            {
                Logger        log = LogManager.GetCurrentClassLogger();
                StringBuilder msg = new StringBuilder();

                Restaurant oldRestaurant = db.Restaurants.Find(newRestaurant.ID);

                oldRestaurant.ID        = newRestaurant.ID;
                oldRestaurant.Name      = newRestaurant.Name;
                oldRestaurant.Address   = newRestaurant.Address;
                oldRestaurant.email     = newRestaurant.email;
                oldRestaurant.phone     = newRestaurant.phone;
                oldRestaurant.AvgRating = newRestaurant.AvgRating;
            }
        }
        public static void DeleteRestaurantByID(int id)
        {
            using (db = new RestaurantReviewsEntities())
            {
                Logger        log = LogManager.GetCurrentClassLogger();
                StringBuilder msg = new StringBuilder();

                Restaurant rest = db.Restaurants.Find(id);

                db.Restaurants.Remove(rest);

                ICollection <Review> reviews = db.Reviews.Where(x => x.id == rest.ID).ToList();
                foreach (Review rev in reviews)
                {
                    db.Reviews.Remove(rev);
                }
            }
        }
Beispiel #13
0
        public static void CreateRestuarant(Restaurant restaurant)
        {
            using (db = new RestaurantReviewsEntities())
            {
                Logger        log = LogManager.GetCurrentClassLogger();
                StringBuilder msg = new StringBuilder();

                db.Restaurants.Add(restaurant);

                try
                {
                    db.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException e)
                {
                    msg.Append(restaurant.name)
                    .Append("--");

                    foreach (var eve in e.EntityValidationErrors)
                    {
                        msg.Append("Entity")
                        .Append(eve.Entry.Entity.GetType().Name)
                        .Append("in state")
                        .Append(eve.Entry.State)
                        .Append("has validation errors.");
                        foreach (var ve in eve.ValidationErrors)
                        {
                            msg.Append("Property")
                            .Append(ve.PropertyName)
                            .Append("Error")
                            .Append(ve.ErrorMessage)
                            .Append("\n");
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }