示例#1
0
 /// <summary>
 /// Add restaurant
 /// </summary>
 /// <returns>Id of added restaurant</returns>
 public int AddRestaurant(Restaurant r)
 {
     using (var db = new RestaurantsEntities())
     {
         db.Restaurants.Add(r);
         db.SaveChanges();
         return(r.id);
     }
 }
示例#2
0
 /// <summary>
 /// Delete restaurant based on id
 /// </summary>
 /// <param name="id">Restaurant id</param>
 public void DeleteRestaurant(int id)
 {
     using (var db = new RestaurantsEntities())
     {
         Restaurant r = GetRestaurantModels().SingleOrDefault(x => x.id == id);
         db.Restaurants.Attach(r);
         db.Restaurants.Remove(r);
         db.SaveChanges();
     }
 }
示例#3
0
        /// <summary>
        /// Edit restaurant based on edited fields
        /// </summary>
        /// <param name="r">Restaurant with updated info</param>
        /// <param name="restaurantId">Restaurant id</param>
        public void EditRestaurant(Restaurant r, int restaurantId)
        {
            using (var db = new RestaurantsEntities())
            {
                Restaurant res = GetRestaurantModels().SingleOrDefault(x => x.id == restaurantId);
                res.Name    = r.Name;
                res.Address = r.Address;

                db.Restaurants.Attach(res);
                db.Entry(res).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
示例#4
0
        /// <summary>
        /// Edit review based on changed fields
        /// </summary>
        /// <param name="r">Review with updated info</param>
        /// <param name="reviewId">Review id</param>
        public void EditReview(Review r, int reviewId)
        {
            using (var db = new RestaurantsEntities())
            {
                Review rev = GetReviewModels().SingleOrDefault(x => x.ReviewId == reviewId);
                rev.Name    = r.Name;
                rev.Rating  = r.Rating;
                rev.Summary = r.Summary;

                db.Reviews.Attach(rev);
                db.Entry(rev).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
示例#5
0
 /// <summary>
 /// Add review to database
 /// </summary>
 /// <returns>Id of added review</returns>
 public void AddReview(Review r)
 {
     try
     {
         using (var db = new RestaurantsEntities())
         {
             db.Reviews.Add(r);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
     }
 }