//Delete a restaurant
        public static void DeleteRestaurant(int id)
        {
            var db = new RestaurantDBEntities1();

            RestaurantReviews.Data.Restaurant dlRest = db.Restaurants.Find(id);
            db.Restaurants.Remove(dlRest);
            db.SaveChanges();
        }
        //Update a restaurant
        public static void UpdateRestaurant(Restaurant rest)
        {
            var db = new RestaurantDBEntities1();

            RestaurantReviews.Data.Restaurant dbRest = db.Restaurants.Find(rest.ID);
            dbRest.Name        = rest.Name;
            dbRest.Address     = rest.Address;
            dbRest.Street      = rest.Street;
            dbRest.City        = rest.City;
            dbRest.State       = rest.State;
            dbRest.Zip         = rest.Zip;
            dbRest.PhoneNumber = rest.PhoneNumber;
            db.SaveChanges();
        }
        //Create a restaurant
        public static void AddRestToDb(Restaurant rest)
        {
            var db = new RestaurantDBEntities1();

            RestaurantReviews.Data.Restaurant dbRest = new RestaurantReviews.Data.Restaurant();
            dbRest.Name        = rest.Name;
            dbRest.Address     = rest.Address;
            dbRest.Street      = rest.Street;
            dbRest.City        = rest.City;
            dbRest.State       = rest.State;
            dbRest.Zip         = rest.Zip;
            dbRest.PhoneNumber = rest.PhoneNumber;
            dbRest.ID          = 90;
            db.Restaurants.Add(dbRest);
            db.SaveChanges();
        }
示例#4
0
        public static Restaurant SetRest(RestaurantReviews.Data.Restaurant dlRest)
        {
            int            restId    = dlRest.ID;
            List <Reviews> revList   = GetRevListById(restId);
            var            restModel = new Restaurant()
            {
                ID          = dlRest.ID,
                Name        = dlRest.Name,
                Address     = dlRest.Address,
                Street      = dlRest.Street,
                City        = dlRest.City,
                State       = dlRest.State,
                PhoneNumber = dlRest.PhoneNumber,
                Zip         = (int)dlRest.Zip,
                reviews     = revList
            };

            restModel.AvgRating = restModel.CalcAvgRating();
            return(restModel);
        }