public IEnumerable <Product> SearchProducts( int?categoryId = null, string categoryName = null, int?brandId = null, decimal?minPrice = null, decimal?maxPrice = null) { var queryString = new QueryString(); if (categoryId != null) { queryString.Add("category_id", categoryId.ToString()); } if (categoryName != null) { queryString.Add("category_name", categoryName); } if (brandId != null) { queryString.Add("brand_id", brandId.ToString()); } if (minPrice != null) { queryString.Add("min_price", minPrice.ToString()); } if (maxPrice != null) { queryString.Add("max_price", maxPrice.ToString()); } var json = _client.DownloadString(string.Format("{0}api/Product{1}{2}", _baseUrl, queryString.Any() ? "?" : "", queryString)); return(JsonConvert.DeserializeObject <IEnumerable <Product> >(json)); }
public RestRequest RemoveQueryStringData(string key) { if (QueryString.Any(t => t.Key == key)) { QueryString.Remove(QueryString.FirstOrDefault(t => t.Key == key)); } return(this); }
public string BuildRelativeUrl() { var url = (Path[0] == '/' ? "" : "/") + Path; if (QueryString != null && QueryString.Any()) { url += "?" + FormUrlEncoder.Encode(QueryString); } return(url); }
public DefaultHttpRequest(HttpMethod method, CanonicalUri canonicalUri, QueryString queryParams, HttpHeaders headers, string body, string bodyContentType) { this.method = method; this.canonicalUri = canonicalUri; bool queryParamsWerePassed = queryParams?.Any() ?? false; if (queryParamsWerePassed) { var mergedQueryString = this.canonicalUri.QueryString.Merge(queryParams); this.canonicalUri = new CanonicalUri(this.canonicalUri.ResourcePath.ToString(), mergedQueryString); } this.headers = headers; if (headers == null) { this.headers = new HttpHeaders(); } this.body = body; this.bodyContentType = bodyContentType; }
private async Task OnLaunchedOrActivatedAsync(IActivatedEventArgs e) { Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { // 创建要充当导航上下文的框架,并导航到第一页 rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: 从之前挂起的应用程序加载状态 } // 将框架放在当前窗口中 Window.Current.Content = rootFrame; } if (e is LaunchActivatedEventArgs) { var args = e as LaunchActivatedEventArgs; if (args.PrelaunchActivated == false) { if (rootFrame.Content == null) { // 当导航堆栈尚未还原时,导航到第一页, // 并通过将所需信息作为导航参数传入来配置 // 参数 rootFrame.Navigate(typeof(LightMainPage), args.Arguments); //rootFrame.Navigate(typeof(MainPage), args.Arguments); } } } else if (e is ToastNotificationActivatedEventArgs) { var toastActivationArgs = e as ToastNotificationActivatedEventArgs; QueryString args = QueryString.Parse(toastActivationArgs.Argument); if (args.Any()) { string msg = toastActivationArgs.UserInput["msg"].ToString().Trim(); if (msg != string.Empty && args["action"] == "reply") { await WtSocket.SendMessageAsync(SocketMessageType.Message, new SendMessageRequestBody { FromType = FromType.User, From = args["from"], ToType = EnumsNET.Enums.Parse <ToType>(args["toType"]), MessageType = MessageType.Text, Client = Client.Win8, IsMarkdown = true, Content = toastActivationArgs.UserInput["msg"].ToString() }); } } // If we're loading the app for the first time, place the main page on // the back stack so that user can go back after they've been // navigated to the specific page //if (rootFrame.BackStack.Count == 0) // rootFrame.BackStack.Add(new PageStackEntry(typeof(MainPage), null, null)); } // 确保当前窗口处于活动状态 Window.Current.Activate(); CustomTitleBar(); }