예제 #1
0
 public void SaveRestaurant(Restaurant restaurant)
 {
     using (var db = new RRContext())
     {
         db.Resturants.Add(restaurant);
         db.SaveChanges();
     }
 }
예제 #2
0
        // find restaurant. create a review save.
        public void SaveReview(Restaurant restaurant, string reviewText, User user)
        {
            using (var db = new RRContext())
            {
                db.Reviews.Add(new Review() { Restaurant = restaurant, ReviewText = reviewText, User = user });

                db.SaveChanges();
            }
        }
예제 #3
0
 public void DeleteReview(int ReviewID)
 {
     using (var db = new RRContext())
     {
         Review review = db.Reviews.Find(ReviewID);
         db.Reviews.Remove(review);
         db.SaveChanges();
     }
 }
예제 #4
0
        public List<string> GetResaurantsByCity(string city)
        {
            using (var db = new RRContext())
            {
                var query = from r in db.Resturants
                            where r.City == city
                            orderby r.Name
                            select r.Name;

                return query.ToList();
            }
        }
예제 #5
0
        private static void Main(string[] args)
        {
            Database.SetInitializer(new InitializeDataBaseWithSeedData());

            Repository repo = new Repository();

            List<string> Names = repo.GetResaurantsByCity("Grove City");

            Console.WriteLine("Restaurants in Grove City");
            foreach (string city in Names)
            {
                Console.WriteLine(city);
            }
            Console.WriteLine();

            Restaurant restaurant = new Restaurant { Name = "Hoss's", City = "Pine Township" };
            repo.SaveRestaurant(restaurant);

            Restaurant rest;
            User user;
            using (var db = new RRContext())
            {
                var query = from r in db.Resturants
                            where r.Name == "Burger King"
                            select r;

                rest = query.SingleOrDefault();

                var query2 = from u in db.Users
                             where u.Name == "Tim"
                             select u;

                user = query2.SingleOrDefault();
            }
            repo.SaveReview(rest, "Good Whopper", user);

            List<RestaurantReviewView> reviews = repo.GetReviewsByUser(1);

            Console.WriteLine("Reviews by UserID = 1");
            foreach (RestaurantReviewView r in reviews)
            {
                Console.WriteLine(r.ReviewText);
            }

            Console.WriteLine();

            repo.DeleteReview(1);

            Console.ReadLine();
            //}
        }
예제 #6
0
        public List<RestaurantReviewView> GetReviewsByUser(int userid)
        {
            using (var db = new RRContext())
            {
                db.Resturants.Load();
                db.Users.Load();
                User user = db.Users.Find(userid);

                var queryReviews = user.Reviews.Select(x => new RestaurantReviewView
                {
                    RestaurantName = x.Restaurant.Name,
                    ReviewerName = x.User.Name,
                    ReviewText = x.ReviewText
                });

                return queryReviews.ToList();
            }
        }