// GET: Restaurants/Create public ActionResult Create() { var result = rr.GetAll(); ViewBag.RestaruantImageURL = new SelectList(result, "RestaruantImageURL", "RestaruantImageURL"); return(View()); }
public ActionResult Search(string searchVal) { RestaurantRepository restaurantRepository = new RestaurantRepository(); // just in case prevent NullPointerException if (searchVal == null) { searchVal = string.Empty; } // compare all words to lower case searchVal = searchVal.ToLower(); // use lambda expression to filter the matched objects List <Restaurant> foundRestarants = restaurantRepository.GetAll() .Where(c => c.Name.ToLower().Contains(searchVal) || c.Description.ToLower().Contains(searchVal)) .ToList(); // convert the DB objects to ViewModel objects List <SearchViewModel> model = new List <SearchViewModel>(); foreach (Restaurant dbRestaurant in foundRestarants) { SearchViewModel modelItem = new SearchViewModel(dbRestaurant); model.Add(modelItem); } return(View(model)); }
public ReviewsIndexVM(ReviewRepository newReviewRepository, RestaurantRepository newRestaurantRepository) { reviewRepository = newReviewRepository; restaurantRepository = newRestaurantRepository; MyReviews = reviewRepository.GetAll().Reverse(); // Most recently created first MyRestaurants = restaurantRepository.GetAll(); }
public ReviewsEditVM(int reviewID, ReviewRepository newReviewRepository, RestaurantRepository newRestaurantRepository) { restaurantRepository = newRestaurantRepository; reviewRepository = newReviewRepository; MyReview = reviewRepository.GetById(reviewID); MyRestaurants = restaurantRepository.GetAll(); }
// GET: Home public ActionResult Index() { RestaurantRepository restaurantRepository = new RestaurantRepository(); List <Restaurant> allRestaurants = restaurantRepository.GetAll(); HomeViewModel model = new HomeViewModel(allRestaurants); return(View(model)); }
public ActionResult Index() { RestaurantListVM model = new RestaurantListVM { Restaurants = _restaurantRepository.GetAll() }; return(View(model)); }
public ReviewsCreateVM(int restaurantID, RestaurantRepository newRestaurantRepository) { restaurantRepository = newRestaurantRepository; MyReview = new Review() { RestaurantID = restaurantID }; MyRestaurants = restaurantRepository.GetAll(); }
public ActionResult Index() { RestaurantRepository repository = new RestaurantRepository(); List <Restaurant> restaurants = repository.GetAll(); RestaurantsListViewModel model = new RestaurantsListViewModel(); model.Restaurants = restaurants; return(View(model)); }
private void RefreshControls() { cmbUsers.ValueMember = "Name"; cmbRestaurants.ValueMember = "Name"; bindingSourceRestaurant.Clear(); bindingSourceRestaurant.DataSource = repositoryRestaurant.GetAll(); cmbRestaurants.DataSource = bindingSourceRestaurant; bindingSourceUser.Clear(); bindingSourceUser.DataSource = repositoryUser.GetAll(); cmbUsers.DataSource = bindingSourceUser; }
private List <SelectListItem> PopulateRestaurantsList() { List <SelectListItem> result = new List <SelectListItem>(); RestaurantRepository restaurantRepo = new RestaurantRepository(); List <Restaurant> restaurants = restaurantRepo.GetAll(); foreach (Restaurant restaurant in restaurants) { SelectListItem item = new SelectListItem(); item.Value = restaurant.ID.ToString(); item.Text = $"{restaurant.Name}"; result.Add(item); } return(result); }
// GET: Restaurant public ActionResult Index() { // if there are some notification message from other actions, then set them in the viewbag // so that we display them in the screen ViewBag.ErrorMessage = TempData["ErrorMessage"]; ViewBag.Message = TempData["Message"]; RestaurantRepository restaurantRepository = new RestaurantRepository(); List <Restaurant> allRestauraurants = restaurantRepository.GetAll(); List <RestaurantViewModel> model = new List <RestaurantViewModel>(); foreach (Restaurant dbRestaurant in allRestauraurants) { RestaurantViewModel restaurantViewModel = new RestaurantViewModel(dbRestaurant); model.Add(restaurantViewModel); } return(View(model)); }
public IHttpActionResult Get() { SocialTapContext context = new SocialTapContext(); Scan sc = new Scan(); sc.Date = DateTime.Today.AddDays(-15); sc.Drink = "Alcohol"; sc.Percentage = 33; sc.Millimeters = 870; sc.Price = 5.80; var d = context.Restaurants.ToList(); sc.Restaurant = d.ElementAt(0); //REIKIA DABARTINIO USERIO var list = context.Users.ToList(); sc.SocialTapUser = list.ElementAt(0); //************************************** context.Scans.Add(sc); context.SaveChanges(); var result = _rep.GetAll(); return(Ok(result)); }
// GET: Restaurants public ActionResult Index(string sort) { IEnumerable <Restaurant> restaurants = restaurantRepository.GetAll(); IEnumerable <Restaurant> tempRestaurants = restaurants.Reverse(); // Most recently created first try { if (sort == "byName") { tempRestaurants = RestaurantService.SortByNameAsc(restaurants); } else if (sort == "byRating") { tempRestaurants = RestaurantService.SortByAvgRatingDesc(restaurants); } else if (sort == "byCuisine") { tempRestaurants = RestaurantService.SortByCuisineAsc(restaurants); } else if (sort == "topThree") { tempRestaurants = RestaurantService.GetTop3(restaurants); } else if (sort != null) { string search = sort; // "sort" var will store search info tempRestaurants = RestaurantService.SearchByName(restaurants, search); } return(View(tempRestaurants)); } catch (Exception e) { log.Error($"[Restaurants Controller] [Index] Exception thrown: {e.Message}"); return(RedirectToAction("Index")); } }
public async Task <IEnumerable <Restaurant> > GetRestaurants() { return(await RestaurantRepository.GetAll()); }
public ReviewsCreateVM(RestaurantRepository newRestaurantRepository) { restaurantRepository = newRestaurantRepository; MyReview = new Review(); MyRestaurants = restaurantRepository.GetAll(); }
public List <UserModelView> AllUsersByAdmin() { ReportRepository reportRepo = new ReportRepository(); RecipeRepository recipeRepo = new RecipeRepository(); PostRepository postRepo = new PostRepository(); RestaurantRepository restRepo = new RestaurantRepository(); List <UserModelView> userModelList = new List <UserModelView>(); foreach (var user in this.GetAll()) { UserModelView umv = new UserModelView(); umv.TotalReport = 0; umv.TotalRecipe = 0; umv.TotalPost = 0; umv.TotalRestaurant = 0; umv.Name = user.Name; umv.Image = user.Image; umv.UserId = user.UserID; //toral report foreach (var report in reportRepo.GetAllReports()) { if (user.UserID == report.ReportedId) { umv.TotalReport += 1; } } //toral recipe foreach (var recipe in recipeRepo.GetAll()) { if (user.UserID == recipe.UserId) { umv.TotalRecipe += 1; } } //toral post foreach (var post in postRepo.GetAll()) { if (user.UserID == post.UserID) { umv.TotalPost += 1; } } //Total Restaurant foreach (var rest in restRepo.GetAll()) { if (user.UserID == rest.UserID) { umv.TotalRestaurant += 1; } } userModelList.Add(umv); } return(userModelList); }
static void Main(string[] args) { // get all cities CategoryRepository categoryRepository = new CategoryRepository(); CityRepository cityRepository = new CityRepository(); List <City> cities = cityRepository.GetAll(); System.Console.WriteLine("The cities are: "); foreach (City item in cities) { System.Console.WriteLine(item.Name); } System.Console.WriteLine(); // search city by ID City city = cityRepository.GetByID(1); System.Console.Write("The city with id=1 is: "); if (city != null) { System.Console.WriteLine(city.Name); } else { System.Console.WriteLine("not found"); } System.Console.WriteLine(); // get all restaurants RestaurantRepository restaurantRepository = new RestaurantRepository(); List <Restaurant> restaurants = restaurantRepository.GetAll(); System.Console.WriteLine("The restaurants are: "); foreach (Restaurant item in restaurants) { string line = string.Format($"{item.Name} - {item.CityName} - {item.CategoryName}"); System.Console.WriteLine(line); } System.Console.WriteLine(); // get all restaurants from the city with id = 1 string cityName = cityRepository.GetByID(1).Name; restaurants = restaurantRepository.GetByCityID(1); System.Console.WriteLine($"The restaurants from {cityName} are: "); foreach (Restaurant item in restaurants) { string line = string.Format("{0} - {1} - {2}", item.Name, item.CityName, item.CategoryName); System.Console.WriteLine(line); } System.Console.WriteLine(); // insert new restaurant Restaurant newRestaurant = new Restaurant(); newRestaurant.Name = "new restaurant"; newRestaurant.CategoryID = 1; newRestaurant.CityID = 2; restaurantRepository.Create(newRestaurant); System.Console.WriteLine(); restaurantRepository.DeleteByID(newRestaurant.ID); System.Console.WriteLine($"The category with ID = 1 is : {categoryRepository.GetByID(1).Name}"); System.Console.Read(); }
static void Main(string[] args) { // get all cities CityRepository cityRepository = new CityRepository(); List <City> cities = cityRepository.GetAll(); System.Console.WriteLine("The cities are: "); foreach (City item in cities) { System.Console.WriteLine(item.Name); } System.Console.WriteLine(); // search city by ID City city = cityRepository.GetByID(1); System.Console.Write("The city with id=1 is: "); if (city != null) { System.Console.WriteLine(city.Name); } else { System.Console.WriteLine("not found"); } System.Console.WriteLine(); // get all restaurants RestaurantRepository restaurantRepository = new RestaurantRepository(); List <Restaurant> restaurants = restaurantRepository.GetAll(); System.Console.WriteLine("The restaurants are: "); foreach (Restaurant item in restaurants) { string line = string.Format("{0} - {1} - {2} - {3} - {4}", item.Name, item.CityName, item.CategoryName, item.Description, item.DateCreated.ToShortDateString()); System.Console.WriteLine(line); } System.Console.WriteLine(); // get all restaurants from Veliko Tarnovo restaurants = restaurantRepository.GetByCityID(1); System.Console.WriteLine("The restaurants from Valiko Tarnovo are: "); foreach (Restaurant item in restaurants) { string line = string.Format("{0} - {1} - {2} - {3} - {4}", item.Name, item.CityName, item.CategoryName, item.Description, item.DateCreated.ToShortDateString()); System.Console.WriteLine(line); } System.Console.WriteLine(); // insert new restaurant Restaurant newRestaurant = new Restaurant(); newRestaurant.Name = "new restaurant"; newRestaurant.Description = "description"; newRestaurant.CategoryID = 1; newRestaurant.CityID = 2; newRestaurant.ImageName = ""; restaurantRepository.Create(newRestaurant); System.Console.WriteLine("added new restaurant. The iD is: " + newRestaurant.ID); System.Console.WriteLine(); //restaurantRepository.DeleteByID(newRestaurant.ID); //System.Console.WriteLine("deleting restaurant with ID = " + newRestaurant.ID); System.Console.Read(); }
public ActionResult Dining() { IEnumerable <Restaurant> information = restaurantRepository.GetAll(); return(View(information)); }
private void RefreshControls() { bindingSourceRestaurant.Clear(); bindingSourceRestaurant.DataSource = repository.GetAll(); dataGridViewRestaurant.DataSource = bindingSourceRestaurant; }
public List <RestaurantModel> GetAll() { return(restaurantRepo.GetAll().ToContracts()); }
public ActionResult GetRestaurants() { return(Json(restaurantRepository.GetAll().ToList(), JsonRequestBehavior.AllowGet)); }
// Returns a custom list of reviews, with RestaurantIDs from 1-10 public static Review[] GenerateReviews(int howMany) { RestaurantRepository restaurantRepository = new RestaurantRepository(); string[] names = new string[4945]; string nameString = System.IO.File.ReadAllText(@"C:\revature\hayes-timothy-project0\LocalGourmet\LocalGourmet.BLL\Configs\Names.txt"); System.IO.StringReader r = new System.IO.StringReader(nameString); for (int i = 0; i < 4945; i++) { names[i] = r.ReadLine(); } Review r1 = new Review("", "I'm never coming here again!", 0, 1, 1, 1); Review r2 = new Review("", "I'd rather eat bread and water.", 1, 2, 1, 0); Review r3 = new Review("", "Bleh!", 1, 2, 1, 2); Review r4 = new Review("", "I hope no one saw me eat here.", 2, 3, 1, 2); Review r5 = new Review("", "Better than starving...", 2, 3, 2, 3); Review r6 = new Review("", "At least it was cheap.", 3, 2, 4, 3); Review r7 = new Review("", "I'd come here again.", 3, 4, 3, 4); Review r8 = new Review("", "I had great expectations...", 2, 3, 4, 4); Review r9 = new Review("", "Wow!", 4, 4, 5, 4); Review r10 = new Review("", "Best restaurant ever!", 5, 5, 5, 5); Review[] revs = new Review[10]; revs[0] = r1; revs[1] = r2; revs[2] = r3; revs[3] = r4; revs[4] = r5; revs[5] = r6; revs[6] = r7; revs[7] = r8; revs[8] = r9; revs[9] = r10; int revIndex; string firstName, lastName; Random rnd = new Random(); Review[] customReviews = new Review[howMany]; for (int i = 0; i < howMany; i++) { revIndex = rnd.Next(10); Review customRev = new Review(); Review q = revs[revIndex]; customRev.Comment = q.Comment; customRev.FoodRating = q.FoodRating; customRev.ServiceRating = q.ServiceRating; customRev.AtmosphereRating = q.AtmosphereRating; customRev.PriceRating = q.PriceRating; firstName = names[rnd.Next(4945)]; lastName = names[rnd.Next(4945)]; customRev.ReviewerName = $"{firstName} {lastName}"; List <int> restIds = restaurantRepository.GetAll().Select(x => x.ID).ToList(); int numRests = restIds.Count; customRev.RestaurantID = restIds[rnd.Next(numRests)]; customReviews[i] = customRev; } return(customReviews); }