public static Restaurant DataToLibrary(RestaurantReviewsData.Restaurant dataModel) { double rating = 0; using (var db = new RestaurantReviewsEntities()) { var reviews = db.Reviews.Where(r => r.restaurantid == dataModel.id); if (reviews.Count() != 0) { rating = reviews.Average(r => r.rating); } } var libModel = new Restaurant() { ID = dataModel.id, Name = dataModel.name, Address = dataModel.address, Phone = dataModel.phone, AverageRating = rating //reviews = (List<Review>) dataModel.Reviews }; return(libModel); }
public static RestaurantReviewsData.Restaurant LibraryToData(Restaurant libModel) { var dataModel = new RestaurantReviewsData.Restaurant() { name = libModel.Name, address = libModel.Address, phone = libModel.Phone }; return(dataModel); }
public static RestaurantReviewsLibrary.Restaurant DataToLibrary(RestaurantReviewsData.Restaurant dataModel) { var libModel = new RestaurantReviewsLibrary.Restaurant() { RestaurantName = dataModel.restaurantName, RestaurantAddress = dataModel.restaurantAddress, RestaurantCity = dataModel.restaurantCity, RestaurantState = dataModel.restaurantState, RestaurantPhoneNumber = dataModel.restaurantPhoneNumber, RestaurantURL = dataModel.restaurantURL, CustomerRating = (float)dataModel.customerRating }; return(libModel); }
public static RestaurantReviewsData.Restaurant LibraryToData(Restaurant libModel) { var dataModel = new RestaurantReviewsData.Restaurant() { restaurantName = libModel.RestaurantName, restaurantAddress = libModel.RestaurantAddress, restaurantCity = libModel.RestaurantCity, restaurantState = libModel.RestaurantState, restaurantPhoneNumber = libModel.RestaurantPhoneNumber, restaurantURL = libModel.RestaurantURL, Reviews = new List <RestaurantReviewsData.Review>() }; List <RestaurantReviewsLibrary.Review> tempList = libModel.GetStoreReviews(); foreach (RestaurantReviewsLibrary.Review r in tempList) { dataModel.Reviews.Add(ReviewOjectToData(r)); } return(dataModel); }
public static RestaurantReviewsLibrary.Restaurant DataToLibrary(RestaurantReviewsData.Restaurant dataModel) { var reviews = ShowAllReviews(dataModel.ID); var libModel = new RestaurantReviewsLibrary.Restaurant() { RestaurantName = dataModel.restaurantName, RestaurantAddress = dataModel.restaurantAddress, RestaurantCity = dataModel.restaurantCity, RestaurantState = dataModel.restaurantState, RestaurantPhoneNumber = dataModel.restaurantPhoneNumber, RestaurantURL = dataModel.restaurantURL, //CustomerRating = (float)dataModel.customerRating, StoreReviews = (List <Review>)reviews, Id = dataModel.ID }; libModel.UpdateRating(); return(libModel); }
//Search Restaurant by id (Update Supplement) public Restaurant getRestaurantById(int idNumber) { Restaurant temp = db.Restaurants.Find(idNumber); return(temp); }
//Read public void ReadRestaurantDetails(int IdNum) { Restaurant rest = getRestaurantById(IdNum); Console.WriteLine(rest.ID + "|| " + rest.restaurantName + "|| " + rest.restaurantAddress + "|| " + rest.restaurantCity + ", " + rest.restaurantState + "|| " + rest.restaurantPhoneNumber + "|| " + rest.restaurantURL + "|| Rating: " + rest.customerRating); }