本文整理汇总了C#中IWebHelper.RemoveQueryString方法的典型用法代码示例。如果您正苦于以下问题:C# IWebHelper.RemoveQueryString方法的具体用法?C# IWebHelper.RemoveQueryString怎么用?C# IWebHelper.RemoveQueryString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWebHelper
的用法示例。
在下文中一共展示了IWebHelper.RemoveQueryString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_remove_queryString_should_ignore_input_parameter_case
public void Can_remove_queryString_should_ignore_input_parameter_case()
{
_httpContext = new FakeHttpContext("~/", "GET", null, null, null, null, null, null);
_webHelper = new WebHelper(_httpContext);
_webHelper.RemoveQueryString("http://www.example.com/?param1=value1&parAm2=value2", "paRAm1")
.ShouldEqual("http://www.example.com/?param2=value2");
}
示例2: Can_remove_queryString
public void Can_remove_queryString()
{
_httpContext = new FakeHttpContext("~/", "GET", null, null, null, null, null, null);
_webHelper = new WebHelper(_httpContext);
//first param (?)
_webHelper.RemoveQueryString("http://www.example.com/?param1=value1¶m2=value2", "param1")
.ShouldEqual("http://www.example.com/?param2=value2");
//second param (&)
_webHelper.RemoveQueryString("http://www.example.com/?param1=value1¶m2=value2", "param2")
.ShouldEqual("http://www.example.com/?param1=value1");
//non-existing param
_webHelper.RemoveQueryString("http://www.example.com/?param1=value1¶m2=value2", "param3")
.ShouldEqual("http://www.example.com/?param1=value1¶m2=value2");
}
示例3: Can_remove_queryString_should_return_lowerCased_result
public void Can_remove_queryString_should_return_lowerCased_result()
{
_httpContext = new FakeHttpContext("~/", "GET", null, null, null, null, null, null);
_webHelper = new WebHelper(_httpContext);
_webHelper.RemoveQueryString("htTp://www.eXAmple.com/?param1=value1&parAm2=value2", "paRAm1")
.ShouldEqual("http://www.example.com/?param2=value2");
}
示例4: PrepareSpecsFilters
public virtual void PrepareSpecsFilters(IList<int> alreadyFilteredSpecOptionIds,
IList<int> filterableSpecificationAttributeOptionIds,
ISpecificationAttributeService specificationAttributeService,
IWebHelper webHelper,
IWorkContext workContext)
{
var allFilters = new List<SpecificationAttributeOptionFilter>();
var specificationAttributeOptions = specificationAttributeService
.GetSpecificationAttributeOptionsByIds(filterableSpecificationAttributeOptionIds != null ?
filterableSpecificationAttributeOptionIds.ToArray() : null);
foreach (var sao in specificationAttributeOptions)
{
var sa = sao.SpecificationAttribute;
if (sa != null)
{
allFilters.Add(new SpecificationAttributeOptionFilter
{
SpecificationAttributeId = sa.Id,
SpecificationAttributeName = sa.GetLocalized(x => x.Name, workContext.WorkingLanguage.Id),
SpecificationAttributeDisplayOrder = sa.DisplayOrder,
SpecificationAttributeOptionId = sao.Id,
SpecificationAttributeOptionName = sao.GetLocalized(x => x.Name, workContext.WorkingLanguage.Id),
SpecificationAttributeOptionDisplayOrder = sao.DisplayOrder
});
}
}
//sort loaded options
allFilters = allFilters.OrderBy(saof => saof.SpecificationAttributeDisplayOrder)
.ThenBy(saof => saof.SpecificationAttributeName)
.ThenBy(saof => saof.SpecificationAttributeOptionDisplayOrder)
.ThenBy(saof => saof.SpecificationAttributeOptionName).ToList();
//get already filtered specification options
var alreadyFilteredOptions = allFilters
.Where(x => alreadyFilteredSpecOptionIds.Contains(x.SpecificationAttributeOptionId))
.Select(x => x)
.ToList();
//get not filtered specification options
var notFilteredOptions = new List<SpecificationAttributeOptionFilter>();
foreach (var saof in allFilters)
{
//do not add already filtered specification options
if (alreadyFilteredOptions.FirstOrDefault(x => x.SpecificationAttributeId == saof.SpecificationAttributeId) != null)
continue;
//else add it
notFilteredOptions.Add(saof);
}
//prepare the model properties
if (alreadyFilteredOptions.Count > 0 || notFilteredOptions.Count > 0)
{
this.Enabled = true;
this.AlreadyFilteredItems = alreadyFilteredOptions.ToList().Select(x =>
{
var item = new SpecificationFilterItem();
item.SpecificationAttributeName = x.SpecificationAttributeName;
item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName;
return item;
}).ToList();
this.NotFilteredItems = notFilteredOptions.ToList().Select(x =>
{
var item = new SpecificationFilterItem();
item.SpecificationAttributeName = x.SpecificationAttributeName;
item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName;
//filter URL
var alreadyFilteredOptionIds = GetAlreadyFilteredSpecOptionIds(webHelper);
if (!alreadyFilteredOptionIds.Contains(x.SpecificationAttributeOptionId))
alreadyFilteredOptionIds.Add(x.SpecificationAttributeOptionId);
string newQueryParam = GenerateFilteredSpecQueryParam(alreadyFilteredOptionIds);
string filterUrl = webHelper.ModifyQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM + "=" + newQueryParam, null);
filterUrl = ExcludeQueryStringParams(filterUrl, webHelper);
item.FilterUrl = filterUrl;
return item;
}).ToList();
//remove filter URL
string removeFilterUrl = webHelper.RemoveQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM);
removeFilterUrl = ExcludeQueryStringParams(removeFilterUrl, webHelper);
this.RemoveFilterUrl = removeFilterUrl;
}
else
{
this.Enabled = false;
}
}
示例5: ExcludeQueryStringParams
protected virtual string ExcludeQueryStringParams(string url, IWebHelper webHelper)
{
var excludedQueryStringParams = "pagenumber"; //remove page filtering
if (!String.IsNullOrEmpty(excludedQueryStringParams))
{
string[] excludedQueryStringParamsSplitted = excludedQueryStringParams.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string exclude in excludedQueryStringParamsSplitted)
{
url = webHelper.RemoveQueryString(url, exclude);
}
}
return url;
}
示例6: LoadPriceRangeFilters
public virtual void LoadPriceRangeFilters(string priceRangeStr, IWebHelper webHelper, IPriceFormatter priceFormatter)
{
var priceRangeList = GetPriceRangeList(priceRangeStr);
if (priceRangeList.Count > 0)
{
this.Enabled = true;
var selectedPriceRange = GetSelectedPriceRange(webHelper, priceRangeStr);
this.Items = priceRangeList.ToList().Select(x =>
{
//from&to
var item = new PriceRangeFilterItem();
if (x.From.HasValue)
item.From = priceFormatter.FormatPrice(x.From.Value, true, false);
if (x.To.HasValue)
item.To = priceFormatter.FormatPrice(x.To.Value, true, false);
string fromQuery = string.Empty;
if (x.From.HasValue)
fromQuery = x.From.Value.ToString(new CultureInfo("en-US"));
string toQuery = string.Empty;
if (x.To.HasValue)
toQuery = x.To.Value.ToString(new CultureInfo("en-US"));
//is selected?
if (selectedPriceRange != null
&& selectedPriceRange.From == x.From
&& selectedPriceRange.To == x.To)
item.Selected = true;
//filter URL
string url = webHelper.ModifyQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM + "=" + fromQuery + "-" + toQuery, null);
url = ExcludeQueryStringParams(url, webHelper);
item.FilterUrl = url;
return item;
}).ToList();
if (selectedPriceRange != null)
{
//remove filter URL
string url = webHelper.RemoveQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM);
url = ExcludeQueryStringParams(url, webHelper);
this.RemoveFilterUrl = url;
}
}
else
{
this.Enabled = false;
}
}
示例7: PrepareSpecsFilters
/// <summary>
/// Prepare model
/// </summary>
/// <param name="alreadyFilteredSpecOptionIds">IDs of already filtered specification options</param>
/// <param name="filterableSpecificationAttributeOptionIds">IDs of filterable specification options</param>
/// <param name="specificationAttributeService"></param>
/// <param name="webHelper">Web helper</param>
/// <param name="workContext">Work context</param>
/// <param name="cacheManager">Cache manager</param>
public virtual void PrepareSpecsFilters(IList<int> alreadyFilteredSpecOptionIds,
int[] filterableSpecificationAttributeOptionIds,
ISpecificationAttributeService specificationAttributeService,
IWebHelper webHelper, IWorkContext workContext, ICacheManager cacheManager)
{
Enabled = false;
var optionIds = filterableSpecificationAttributeOptionIds != null
? string.Join(",", filterableSpecificationAttributeOptionIds) : string.Empty;
var cacheKey = string.Format(ModelCacheEventConsumer.SPECS_FILTER_MODEL_KEY, optionIds, workContext.WorkingLanguage.Id);
var allOptions = specificationAttributeService.GetSpecificationAttributeOptionsByIds(filterableSpecificationAttributeOptionIds);
var allFilters = cacheManager.Get(cacheKey, () => allOptions.Select(sao =>
new SpecificationAttributeOptionFilter
{
SpecificationAttributeId = sao.SpecificationAttribute.Id,
SpecificationAttributeName = sao.SpecificationAttribute.GetLocalized(x => x.Name, workContext.WorkingLanguage.Id),
SpecificationAttributeDisplayOrder = sao.SpecificationAttribute.DisplayOrder,
SpecificationAttributeOptionId = sao.Id,
SpecificationAttributeOptionName = sao.GetLocalized(x => x.Name, workContext.WorkingLanguage.Id),
SpecificationAttributeOptionColorRgb = sao.ColorSquaresRgb,
SpecificationAttributeOptionDisplayOrder = sao.DisplayOrder
}).ToList());
if (!allFilters.Any())
return;
//sort loaded options
allFilters = allFilters.OrderBy(saof => saof.SpecificationAttributeDisplayOrder)
.ThenBy(saof => saof.SpecificationAttributeName)
.ThenBy(saof => saof.SpecificationAttributeOptionDisplayOrder)
.ThenBy(saof => saof.SpecificationAttributeOptionName).ToList();
//prepare the model properties
Enabled = true;
var removeFilterUrl = webHelper.RemoveQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM);
RemoveFilterUrl = ExcludeQueryStringParams(removeFilterUrl, webHelper);
//get already filtered specification options
var alreadyFilteredOptions = allFilters.Where(x => alreadyFilteredSpecOptionIds.Contains(x.SpecificationAttributeOptionId));
AlreadyFilteredItems = alreadyFilteredOptions.Select(x =>
new SpecificationFilterItem
{
SpecificationAttributeName = x.SpecificationAttributeName,
SpecificationAttributeOptionName = x.SpecificationAttributeOptionName,
SpecificationAttributeOptionColorRgb = x.SpecificationAttributeOptionColorRgb
}).ToList();
//get not filtered specification options
NotFilteredItems = allFilters.Except(alreadyFilteredOptions).Select(x =>
{
//filter URL
var alreadyFiltered = alreadyFilteredSpecOptionIds.Concat(new List<int> { x.SpecificationAttributeOptionId });
var queryString = string.Format("{0}={1}", QUERYSTRINGPARAM, GenerateFilteredSpecQueryParam(alreadyFiltered.ToList()));
var filterUrl = webHelper.ModifyQueryString(webHelper.GetThisPageUrl(true), queryString, null);
return new SpecificationFilterItem()
{
SpecificationAttributeName = x.SpecificationAttributeName,
SpecificationAttributeOptionName = x.SpecificationAttributeOptionName,
SpecificationAttributeOptionColorRgb = x.SpecificationAttributeOptionColorRgb,
FilterUrl = ExcludeQueryStringParams(filterUrl, webHelper)
};
}).ToList();
}
示例8: ExcludeQueryStringParams
/// <summary>
/// Exclude query string parameters
/// </summary>
/// <param name="url">URL</param>
/// <param name="webHelper">Web helper</param>
/// <returns>New URL</returns>
protected virtual string ExcludeQueryStringParams(string url, IWebHelper webHelper)
{
//comma separated list of parameters to exclude
const string excludedQueryStringParams = "pagenumber";
var excludedQueryStringParamsSplitted = excludedQueryStringParams.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string exclude in excludedQueryStringParamsSplitted)
url = webHelper.RemoveQueryString(url, exclude);
return url;
}
示例9: LoadSpecsFilters
public virtual void LoadSpecsFilters(Category category,
ISpecificationAttributeService specificationAttributeService, IWebHelper webHelper,
IWorkContext workContext)
{
if (category == null)
throw new ArgumentNullException("category");
var alreadyFilteredOptions = GetAlreadyFilteredSpecs(specificationAttributeService, webHelper, workContext);
var notFilteredOptions = GetNotFilteredSpecs(category.Id,
specificationAttributeService, webHelper, workContext);
if (alreadyFilteredOptions.Count > 0 || notFilteredOptions.Count > 0)
{
this.Enabled = true;
this.AlreadyFilteredItems = alreadyFilteredOptions.ToList().Select(x =>
{
var item = new SpecificationFilterItem();
item.SpecificationAttributeName = x.SpecificationAttributeName;
item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName;
return item;
}).ToList();
this.NotFilteredItems = notFilteredOptions.ToList().Select(x =>
{
var item = new SpecificationFilterItem();
item.SpecificationAttributeName = x.SpecificationAttributeName;
item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName;
//filter URL
var alreadyFilteredOptionIds = GetAlreadyFilteredSpecOptionIds(webHelper);
if (!alreadyFilteredOptionIds.Contains(x.SpecificationAttributeOptionId))
alreadyFilteredOptionIds.Add(x.SpecificationAttributeOptionId);
string newQueryParam = GenerateFilteredSpecQueryParam(alreadyFilteredOptionIds);
string filterUrl = webHelper.ModifyQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM + "=" + newQueryParam, null);
filterUrl = ExcludeQueryStringParams(filterUrl, webHelper);
item.FilterUrl = filterUrl;
return item;
}).ToList();
//remove filter URL
string removeFilterUrl = webHelper.RemoveQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM);
removeFilterUrl = ExcludeQueryStringParams(removeFilterUrl, webHelper);
this.RemoveFilterUrl = removeFilterUrl;
}
else
{
this.Enabled = false;
}
}
示例10: PrepareSpecsFilters
public virtual void PrepareSpecsFilters(IList<string> alreadyFilteredSpecOptionIds,
IList<string> filterableSpecificationAttributeOptionIds,
ISpecificationAttributeService specificationAttributeService,
IWebHelper webHelper,
IWorkContext workContext,
ICacheManager cacheManager)
{
string cacheKey = string.Format(ModelCacheEventConsumer.SPECS_FILTER_MODEL_KEY,
filterableSpecificationAttributeOptionIds != null ? string.Join(",", filterableSpecificationAttributeOptionIds) : "",
workContext.WorkingLanguage.Id);
var allFilters = cacheManager.Get(cacheKey, () =>
{
var _allFilters = new List<SpecificationAttributeOptionFilter>();
foreach (var sao in filterableSpecificationAttributeOptionIds)
{
int _specificationAttributeId = Convert.ToInt32(sao.Split(':').FirstOrDefault().ToString());
int _specificationAttributeOptionId = Convert.ToInt32(sao.Split(':').LastOrDefault().ToString());
var sa = EngineContext.Current.Resolve<ISpecificationAttributeService>().GetSpecificationAttributeById(_specificationAttributeId);
if (sa != null)
{
_allFilters.Add(new SpecificationAttributeOptionFilter
{
SpecificationAttributeId = sa.Id,
SpecificationAttributeName = sa.GetLocalized(x => x.Name, workContext.WorkingLanguage.Id),
SpecificationAttributeDisplayOrder = sa.DisplayOrder,
SpecificationAttributeOptionId = sao, //_specificationAttributeOptionId.ToString(), //sa.SpecificationAttributeOptions.FirstOrDefault(x=>x.Id == ),
SpecificationAttributeOptionName = sa.SpecificationAttributeOptions.FirstOrDefault(x => x.Id == _specificationAttributeOptionId).GetLocalized(x => x.Name, workContext.WorkingLanguage.Id),
SpecificationAttributeOptionDisplayOrder = sa.SpecificationAttributeOptions.FirstOrDefault(x => x.Id == _specificationAttributeOptionId).DisplayOrder
});
}
}
return _allFilters.ToList();
});
//sort loaded options
allFilters = allFilters.OrderBy(saof => saof.SpecificationAttributeDisplayOrder)
.ThenBy(saof => saof.SpecificationAttributeName)
.ThenBy(saof => saof.SpecificationAttributeOptionDisplayOrder)
.ThenBy(saof => saof.SpecificationAttributeOptionName).ToList();
//get already filtered specification options
var alreadyFilteredOptions = allFilters
.Where(x => alreadyFilteredSpecOptionIds.Contains(x.SpecificationAttributeOptionId))
.Select(x => x)
.ToList();
//get not filtered specification options
var notFilteredOptions = new List<SpecificationAttributeOptionFilter>();
foreach (var saof in allFilters)
{
//do not add already filtered specification options
if (alreadyFilteredOptions.FirstOrDefault(x => x.SpecificationAttributeId == saof.SpecificationAttributeId) != null)
continue;
//else add it
notFilteredOptions.Add(saof);
}
//prepare the model properties
if (alreadyFilteredOptions.Count > 0 || notFilteredOptions.Count > 0)
{
this.Enabled = true;
this.AlreadyFilteredItems = alreadyFilteredOptions.ToList().Select(x =>
{
var item = new SpecificationFilterItem();
item.SpecificationAttributeName = x.SpecificationAttributeName;
item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName;
return item;
}).ToList();
this.NotFilteredItems = notFilteredOptions.ToList().Select(x =>
{
var item = new SpecificationFilterItem();
item.SpecificationAttributeName = x.SpecificationAttributeName;
item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName;
//filter URL
var alreadyFilteredOptionIds = GetAlreadyFilteredSpecOptionIds(webHelper);
if (!alreadyFilteredOptionIds.Contains(x.SpecificationAttributeOptionId.ToString()))
alreadyFilteredOptionIds.Add(x.SpecificationAttributeOptionId.ToString());
string newQueryParam = GenerateFilteredSpecQueryParam(alreadyFilteredOptionIds);
string filterUrl = webHelper.ModifyQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM + "=" + newQueryParam, null);
filterUrl = ExcludeQueryStringParams(filterUrl, webHelper);
item.FilterUrl = filterUrl;
return item;
}).ToList();
//remove filter URL
string removeFilterUrl = webHelper.RemoveQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM);
removeFilterUrl = ExcludeQueryStringParams(removeFilterUrl, webHelper);
this.RemoveFilterUrl = removeFilterUrl;
}
else
{
this.Enabled = false;
}
//.........这里部分代码省略.........