public ActionResult Index( [ModelBinder(typeof(StringArrayModelBinder))]string[] categories, [ModelBinder(typeof(StringArrayModelBinder))]string[] subcategories, string responsetime, string authorrating, bool onlyData = false, int page = 1) { var user = _userRepository.GetByUsername(User.Identity.Name); var userid = ""; if (user != null) userid = user.Id; double userRatingFrom = 0; double userRatingTo = 5; if (categories == null) categories = new[] {"All"}; if (subcategories == null) subcategories = new string[0]; if (string.IsNullOrEmpty(responsetime)) responsetime = "ResponseTimeAny"; if (!string.IsNullOrEmpty(authorrating)) { var ratingSplitted = authorrating.Split(','); if (ratingSplitted.Length == 2) { double.TryParse(ratingSplitted[0].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out userRatingFrom); double.TryParse(ratingSplitted[1].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out userRatingTo); } } var categoriesWithSub = _categoryRepository.GetAllWithSybCategories(); ViewBag.Categories = categoriesWithSub; long[] сategoryIds = null; long[] subсategoryIds = null; if (!categories.ContainsIgnoreCase("All")) { сategoryIds = categories.Select(x => {long value; return long.TryParse(x, out value) ? value : 0; }).ToArray(); subсategoryIds = subcategories.Select(x => { long value; return long.TryParse(x, out value) ? value : 0; }).ToArray(); } var searchData = new SearchListParams { CategoryIds = сategoryIds, SubcategoryIds = subсategoryIds, GigResponseTime = responsetime, UserRatingFrom = userRatingFrom, UserRatingTo = userRatingTo, OrderBy = "new", UserFilter = "" }; var totalCount = _searchRepository.ListCount(searchData); var totalPages = Math.Ceiling(totalCount / (decimal)PageSize); var skip = (page - 1) * PageSize; List<Order> orders = _searchRepository.List(searchData, skip, PageSize, userid); var model = new StaticSearchModel { Categories = categories, Subcategories = subcategories, Orders = orders, Page = page, TotalPages = totalPages }; if (onlyData) return PartialView("_OrdersContainer", model); return View("Index", model); }
public ActionResult QuickSearch(string data) { var results = new List<QuickSearchItemModel>(); var categories = _categoryRepository.SearchByName(data); foreach (var category in categories) { var subcats = string.Join(",", category.Subcategories.Select(x => x.Id.ToString())); results.Add(new QuickSearchItemModel { Content = category.SelectorContent, Url = "/search/index?categories=" + category.Id + "&subcategories=" + subcats }); } var searchData = new SearchListParams { GigResponseTime = "ResponseTimeAny", UserRatingFrom = 0, UserRatingTo = 5, OrderBy = "highrating", UserFilter = "", Title = data }; var gigs = _searchRepository.List(searchData, 0, 6, string.Empty); foreach (var gig in gigs) { var item = new QuickSearchItemModel { Content = string.Format("{0}{1}", gig.Category.SelectorContent, gig.Title), Img = gig.FirstImage }; item.Url = "/orders/view/" + gig.Id; results.Add(item); } return new JsonResult { Data = results, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }