public ActionResult BrandIndex(string brand, string city, string area, string word, int page = 1) { page = page <= 0 ? 1 : page; ViewBag.PageIndex = page; ViewBag.PageSize = 10; ViewData["brand"] = brand; ViewData["city"] = city; ViewData["area"] = area; ViewData["word"] = word; ViewBag.BrandModel = BrandList.List.FirstOrDefault(x => x.Py == brand); ViewBag.BrandName = ViewBag.BrandModel?.Name ?? string.Empty; var request = new StoreSearchRequest { Area = area, Brand = brand, City = city, PageSize = ViewBag.PageSize, PageIndex = ViewBag.PageIndex, SearchKey = word }; ViewBag.AreaList = HotCityList.List; var list = new List <StoreSearchModel>(); var data = StoresAccess.GetStoreList(request); ViewBag.Total = data?.Count ?? 0; if (data != null && data.Any()) { data = data.Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize).ToList(); list = StoresAccess.ConvertList(data); } ViewBag.List = list; return(View()); }
/// <summary> /// Return stores using the request /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <StoreSearchResponse> StoreSearchAsync(StoreSearchRequest request) { StoreSearchResponse storeSearchResponse = null; string payload = string.Format(STORE_SEARCH_PAYLOAD, request.SearchText, string.Empty); int tries = 3; bool failed = false; do { tries--; failed = false; try { IRestRequest restRequest = new RestRequest(STORES_GRAPHQL_ENDPOINT, Method.POST); restRequest.AddParameter("application/json", payload, ParameterType.RequestBody); restRequest.AddCookie("_", "_"); //a cookie is required by the request contract, //restsharp requires that this not be an empty string in order for the header be set IRestResponse <StoreSearchResponse> restResponse = await _client.ExecutePostTaskAsync <StoreSearchResponse>(restRequest); storeSearchResponse = restResponse.Data; } catch (JsonReaderException) { failed = true; } }while (tries > 0 && failed); return(storeSearchResponse); }
public ActionResult Index() { var mvcName = typeof(Controller).Assembly.GetName(); var isMono = Type.GetType("Mono.Runtime") != null; ViewData["Version"] = mvcName.Version.Major + "." + mvcName.Version.Minor; ViewData["Runtime"] = isMono ? "Mono" : ".NET"; var ipCity = IPHelper.GetIPCitys()?.ToLower(); if (string.IsNullOrEmpty(ipCity) || ipCity == "未知" || ipCity == "内网ip") { ipCity = "苏州"; } var request = new StoreSearchRequest { City = ipCity, PageSize = 4, }; var list = new List <StoreSearchModel>(); var data = StoresAccess.GetStoreList(request); if (data != null && data.Any()) { data = data.Take(request.PageSize).ToList(); list = StoresAccess.ConvertList(data); } ViewBag.List = list; ViewBag.AreaList = HotCityList.List; return(View()); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "KrogerCompare/StoreSearch/")] HttpRequestMessage req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); KrogerClient client = Startup.KrogerClient; StoreSearchRequest storeSearchRequest = JsonConvert.DeserializeObject <StoreSearchRequest>(req.Content.ReadAsStringAsync().Result); StoreSearchResponse storeSearchResponse = await client.StoreSearchAsync(storeSearchRequest); return(req.CreateResponse(HttpStatusCode.OK, storeSearchResponse)); }
/// <summary> /// 列表页 /// </summary> /// <param name="request"></param> /// <returns></returns> public JsonResult GetStoreList(StoreSearchRequest request) { var list = new List <StoreSearchModel>(); var data = StoresAccess.GetStoreList(request); if (data != null && data.Any()) { data = data.Take(request.PageSize).ToList(); list = StoresAccess.ConvertList(data); } return(Json(list, JsonRequestBehavior.AllowGet)); }
public ActionResult CityIndex(string city, string area) { var areaModel = new AreaFilteMobdel(); if (!string.IsNullOrEmpty(area)) { areaModel = StoresAccess.GetAreaFilter(area); } else if (!string.IsNullOrEmpty(city)) { areaModel = StoresAccess.GetAreaFilter(city); } if (areaModel == null || areaModel.AreaType == 0) { return(Redirect("/")); } ViewBag.CityName = areaModel?.CityName ?? string.Empty; ViewBag.CityPy = areaModel?.CityNamePy ?? string.Empty; ViewBag.AreaPy = areaModel?.AreaNamePy ?? string.Empty; ViewBag.AreaName = areaModel?.AreaName ?? string.Empty; ViewBag.AreaList = HotCityList.List; var request = new StoreSearchRequest { Area = area, City = city, }; var cityList = new List <CityBrandModel>(); var data = StoresAccess.GetStoreList(request); if (data != null && data.Count > 0) { BrandList.List.ForEach(x => { var bData = data.Where(d => d.brand == x.Id).OrderBy(d => d.sortby).ToList(); if (bData != null && bData.Count > 0) { var cityModel = new CityBrandModel { Brand = x.Id, BrandName = x.Name, List = new List <StoreSearchModel>() }; bData = bData.Take(4).ToList(); cityModel.List.AddRange(StoresAccess.ConvertList(bData)); cityList.Add(cityModel); } }); } ViewBag.CityList = cityList; return(View()); }
/// <summary> /// 获取店铺详情页面 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Detail(int id) { var model = StoresAccess.GetStoresDetail(id); ViewBag.store = model; ViewBag.BrandModel = BrandList.GetModel(model.brand); ViewBag.brand = ViewBag.BrandModel.Py; var request = new StoreSearchRequest { City = model.city, Brand = ViewBag.BrandModel.Py, PageSize = 4, }; var list = new List <StoreSearchModel>(); var data = StoresAccess.GetStoreList(request); if (data != null && data.Any()) { data = data.Where(x => x.Id != id).Take(request.PageSize).ToList(); list = StoresAccess.ConvertList(data); } ViewBag.List = list; return(View()); }
/// <summary> /// 获取门店列表 /// </summary> /// <param name="request"></param> public static List <StoresModel> GetStoreList(StoreSearchRequest request) { var list = new List <StoresModel>(); var bi = GetBrandInt(request.Brand); DataTable dt = new DataTable(); try { StringBuilder getsql = new StringBuilder(); getsql.Append(" SELECT * FROM stores WHERE 1=1 "); if (bi > 0) { getsql.Append($" AND brand = {bi} "); } if (!string.IsNullOrEmpty(request.City)) { getsql.Append($" AND city = '{request.City}' "); } if (!string.IsNullOrEmpty(request.Area)) { getsql.Append($" AND district = '{request.Area}' "); } if (!string.IsNullOrEmpty(request.SearchKey)) { getsql.Append($" AND storeName Like '%{request.SearchKey}%' "); } getsql.Append($" Order by sortby asc "); dt = MySqlHelper.Query(getsql.ToString())?.Tables[0]; list = GetStoresModelList(dt); } catch (Exception ex) { } return(list); }
/// <summary> /// Synchronously fetch stores using the request /// </summary> /// <param name="request"></param> /// <returns></returns> public StoreSearchResponse StoreSearch(StoreSearchRequest request) { return(StoreSearchAsync(request).Result); }