public static DataLayer.Models.RestaurantModel ToData(RestaurantsClass classrest)
        {
            var DataRestaurant = new DataLayer.Models.RestaurantModel()
            {
                RestID     = classrest.RestID,
                Restaurant = classrest.Restaurant,
                Address    = classrest.Address,
                City       = classrest.City,
                Rating     = classrest.Rating,
                Cuisine    = classrest.Cuisine,
                Created    = classrest.Created,
                Modified   = classrest.Modified
            };

            return(DataRestaurant);
        }
        public static RestaurantsClass ToWeb(DataLayer.Models.RestaurantModel dataRestaurant)
        {
            decimal rating = 0;

            using (var db = new RestDbContent())
            {
                var review = db.reviews.Where(r => r.RestID == dataRestaurant.RestID);
                if (review.Count() != 0)
                {
                    rating = review.Average(r => r.Rating);
                }
            }
            var webRest = new RestaurantsClass()
            {
                RestID      = dataRestaurant.RestID,
                Restaurant  = dataRestaurant.Restaurant,
                Address     = dataRestaurant.Address,
                City        = dataRestaurant.City,
                Rating      = rating,
                Cuisine     = dataRestaurant.Cuisine,
                ReviewModel = new List <ReviewModel>()
            };

            foreach (var review in dataRestaurant.ReviewModel)
            {
                var temp = new ReviewModel
                {
                    RevID      = review.RevID,
                    RestID     = review.RestID,
                    UserID     = review.UserID,
                    Review     = review.Review,
                    Rating     = review.Rating,
                    Restaurant = review.Restaurant
                };

                webRest.ReviewModel.Add(temp);
            }

            return(webRest);
        }
 public void Delete(RestaurantsClass restaurantclass)
 {
     crud.RemoveRestaurant(ToData(restaurantclass));
 }
 public void Update(RestaurantsClass restaurantclass)
 {
     crud.UpdateRestaurant(ToData(restaurantclass));
 }
 public void Add(RestaurantsClass restaurantclass)
 {
     crud.AddRestaurant(ToData(restaurantclass));
 }