public void AddNewReview(int id, Review newReview)
 {
     newReview.RestaurantId = id;
     newReview.reviewer     = "";
     _db.Reviews.Add(ToDataReview(newReview));
     //_db.SaveChanges();
     try
     {
         _db.SaveChanges();
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
     {
         Exception raise = dbEx;
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 string message = string.Format("{0}:{1}",
                                                validationErrors.Entry.Entity.ToString(),
                                                validationError.ErrorMessage);
                 // raise a new exception nesting
                 // the current instance as InnerException
                 raise = new InvalidOperationException(message, raise);
             }
         }
         throw raise;
     }
 }
 public void AddRestaurant(Restaurant item)
 {
     using (var db = new RestaurantsDBEntities())
     {
         db.Restaurants.Add(LibraryToData(item));
         db.SaveChanges();
     }
 }
 public void RemoveRestaurant(int id)
 {
     using (var db = new RestaurantsDBEntities())
     {
         var tempRestaurant = db.Restaurants.Where(x => x.ID == id).ToList()[0];
         db.Restaurants.Remove(tempRestaurant);
         db.SaveChanges();
     }
 }
 public double ShowAverageRating(int restId)
 {
     using (var db = new RestaurantsDBEntities())
     {
         double RatingAverage = db.Reviews.Where(r => r.RestaurantId == restId).Average(r => r.rating);
         var    temp          = db.Restaurants.Where(x => x.ID == restId).First();
         temp.avgRating = RatingAverage;
         db.SaveChanges();
         return(RatingAverage);
     }
 }
 public void UpdateRestaurant(Restaurant item)
 {
     using (var db = new RestaurantsDBEntities())
     {
         Restaurant restaurant = new Restaurant();
         var        temp       = db.Restaurants.Find(item.ID);
         restaurant.ID          = temp.ID;
         restaurant.name        = temp.name;
         restaurant.address     = temp.address;
         restaurant.city        = temp.city;
         restaurant.state       = temp.state;
         restaurant.zipCode     = temp.zipCode;
         restaurant.phoneNumber = temp.phoneNumber;
         restaurant.avgRating   = temp.avgRating;
         db.Restaurants.Add(LibraryToData(restaurant));
         db.SaveChanges();
     }
 }
        public double UpdateAverageRating(int restId)
        {
            using (var db = new RestaurantsDBEntities())
            {
                double RatingAverage = db.Reviews.Where(r => r.RestaurantId == restId).Average(r => (double?)r.rating) ?? 0;
                var    temp          = db.Restaurants.Where(x => x.ID == restId).First();
                temp.avgRating = RatingAverage;
                db.SaveChanges();
                return(RatingAverage);
            }

            //double cafeSales = db.InvoiceLines
            //         .Where(x =>
            //                    x.UserId == user.UserId &&
            //                    x.DateCharged >= dateStart &&
            //                    x.DateCharged <= dateEnd)
            //         .Sum(x => (double?)(x.Quantity * x.Price)) ?? 0;
        }
Пример #7
0
 public void Create(T entity)
 {
     Context.Set <T>().Add(entity);
     Context.SaveChanges();
 }
Пример #8
0
        public void AddNewReview(Review newReview)
        {
            _db.Reviews.Add(ToDataReview(newReview));

            _db.SaveChanges();
        }