public ActionResult Index(int id = 0) { if (id <= 0) { id = 1; } var model = this.HttpContext.Cache[string.Format("Sportcenters by page: {0}", id)]; if (model == null) { model = sportCenterService.All() .OrderByDescending(x => x.Rating.Total) .Skip((id - 1) * (int)ViewBag.ItemsPerPage) .Take((int)ViewBag.ItemsPerPage) .To <SportCenterViewModel>() .ToList(); this.HttpContext.Cache.Insert( string.Format("Sportcenters by page: {0}", id), model, null, DateTime.Now.AddSeconds(10), TimeSpan.Zero ); } foreach (var sportCenter in (IEnumerable <SportCenterViewModel>)model) { sportCenter.Images = ImageHelper.SanitizeImageUrls(sportCenterService.GetImagesForSportCenter(sportCenter.Name).ToArray()); } return(View(model)); }
public ActionResult SportCenters() { var all = sportCenterService.All().To <SportCenterViewModel>().ToList(); Response.Write("All sport centers are: " + all.Count()); return(View()); }
public HomeController( ISportCategoryService sportCategories, IAddressService addressService, ISportCategoryService categoryService, ISportCenterService sportCenterService, IUserService usersService) : base(sportCategories, addressService, categoryService) { this.sportCenterService = sportCenterService; this.usersService = usersService; ViewBag.AllSportCentersCount = sportCenterService.All().Count(); ViewBag.ItemsPerPage = 4; }
public ActionResult ByPreferance(SearchViewModel model) { string city = string.Empty; string neighbour = string.Empty; if (model.City != 0) { city = addressService.All().FirstOrDefault(x => x.Id == model.City).City; } if (model.Neighborhood != 0) { neighbour = addressService.All().FirstOrDefault(x => x.Id == model.Neighborhood).Neighborhood; } var cityOrNeighbourPassed = (city != string.Empty || neighbour != string.Empty); var fromCitiesAndNeihbours = sportCenterService.All() .Where(x => city != string.Empty ? x.Address.City == city : x.Address.City == null) .Where(x => neighbour != string.Empty ? x.Address.Neighborhood == neighbour : x.Address.Neighborhood == null) .To <SportCenterViewModel>() .ToList(); // cities and neighbours if (string.IsNullOrEmpty(neighbour)) { fromCitiesAndNeihbours = sportCenterService.All() .Where(x => city != string.Empty ? x.Address.City == city : x.Address.City == null) .To <SportCenterViewModel>() .ToList(); } // categories var categoriesNames = new List <string>(); if (model.SportCategories != null) { categoriesNames = Array .ConvertAll(model.SportCategories.Split(','), p => p.Trim()).Where(x => !string.IsNullOrEmpty(x)).ToList(); } var fromCategories = new List <SportCenterViewModel>(); foreach (var category in categoriesNames) { var current = categoryService.All() .FirstOrDefault(x => x.Name == category); if (current != null) { fromCategories.AddRange(current.SportCenters .AsQueryable() .To <SportCenterViewModel>().ToList()); } } var resultSportCenters = new List <SportCenterViewModel>(); if (fromCitiesAndNeihbours.Count > 0 && fromCategories.Count > 0) { resultSportCenters = fromCitiesAndNeihbours .Where(x => fromCategories.Any(y => y.Name == x.Name)) .ToList(); } else if (fromCategories.Count > 0 && !cityOrNeighbourPassed) { resultSportCenters = fromCategories; } else if (cityOrNeighbourPassed) { resultSportCenters = fromCitiesAndNeihbours .Where(x => city != string.Empty ? x.Address.City == city : x.Address.City != null) .Where(x => neighbour != string.Empty ? x.Address.Neighborhood == neighbour : x.Address.Neighborhood != null) .ToList(); } this.GetImageUrls(resultSportCenters); return(View(resultSportCenters)); }