Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 布尔房地产展真实&;虚假项目_C#_.net_Umbraco_Umbraco7 - Fatal编程技术网

C# 布尔房地产展真实&;虚假项目

C# 布尔房地产展真实&;虚假项目,c#,.net,umbraco,umbraco7,C#,.net,Umbraco,Umbraco7,我在翁布拉科7号工作。我的问题是左侧的“性别”过滤,这是一个bool(queryString)。该bool在每个产品上设置为“该产品适合男性吗?-正确或错误” 全性别=无 男性=&性别=真 女性=&性别=错误 默认情况下,它设置为“所有性别”,但在代码中,它实际上设置为true,正如您在我的代码中看到的那样。我想同时展示true和false产品 boolisMale=true应该类似于isMale=true&&false,如果这有意义的话 <div id="categoryCollec

我在翁布拉科7号工作。我的问题是左侧的“性别”过滤,这是一个
bool
(queryString)。该bool在每个产品上设置为“该产品适合男性吗?-正确或错误”

  • 全性别=无
  • 男性=&性别=真
  • 女性=&性别=错误
默认情况下,它设置为“所有性别”,但在代码中,它实际上设置为
true
,正如您在我的代码中看到的那样。我想同时展示
true
false
产品

bool
isMale=true
应该类似于
isMale=true&&false
,如果这有意义的话

<div id="categoryCollection">

@{
    bool isMale = true;
}

@if (!string.IsNullOrEmpty(selectedpriceRange) && selectedpriceRange.Contains("-"))
{
    string[] priceArray = selectedpriceRange.Split('-');
    int minPrice = 0;
    int maxPrice = 0;

    if (queryString.Get("gender") != null)
    {
        isMale = bool.Parse(queryString.Get("gender"));
    }

    if (priceArray.Count() == 2 && int.TryParse(priceArray[0], out minPrice) && int.TryParse(priceArray[1], out maxPrice))
    {
        selectedItems.AddRange(productTypes
            .Where(x => x.HasValue("price") &&
            x.GetPropertyValue<int>("price") > minPrice &&
            x.GetPropertyValue<int>("price") < maxPrice &&
            x.HasValue("gender") &&
            x.GetPropertyValue<bool>("gender") == isMale)
            .Skip((page - 1) * pageSize).Take(pageSize));

        foreach (var item in selectedItems.Skip((page - 1) * pageSize).Take(pageSize))
        {
            /* If pricerange is selected */
            @buildItemProduct(item);
        }
    }
}
else
{
    if (queryString.Get("gender") != null)
    {
        isMale = bool.Parse(queryString.Get("gender"));
    }
    selectedItems.AddRange(productTypes.Where(x => x.HasValue("gender") && x.GetPropertyValue<bool>("gender") == isMale));

    foreach (var item in selectedItems.Skip((page - 1) * pageSize).Take(pageSize))
    {
        /* If pricerange is selected */
        @buildItemProduct(item);
    }
}
</div>

@{
布尔伊斯梅尔=真;
}
@如果(!string.IsNullOrEmpty(selectedpriceRange)&&selectedpriceRange.Contains(“-”)包含
{
字符串[]priceArray=selectedpriceRange.Split('-');
int minPrice=0;
int maxPrice=0;
if(queryString.Get(“性别”)!=null)
{
isMale=bool.Parse(queryString.Get(“性别”));
}
if(priceArray.Count()==2&&int.TryParse(priceArray[0],out-minPrice)&&int.TryParse(priceArray[1],out-maxPrice))
{
选择EditEMS.AddRange(产品类型
其中(x=>x.HasValue(“价格”)&&
x、 GetPropertyValue(“价格”)>minPrice&&
x、 GetPropertyValue(“价格”)x.HasValue(“性别”)&&x.GetPropertyValue(“性别”)==isMale));
foreach(selectedItems.Skip((第1页)*pageSize.Take中的变量项)(pageSize))
{
/*如果选择了pricerange*/
@buildItemProduct(项目);
}
}
如果你想看我的全部代码,你可以看


我不知道如何声明“isMale”以同时显示真假产品。

您可以使用另一个bool来保持最小的更改:

//...
var bothGender = true;
if (queryString.Get("gender") != null)
{
    isMale = bool.Parse(queryString.Get("gender"));
    bothGender = false;
}

if (priceArray.Count() == 2 && int.TryParse(priceArray[0], out minPrice) && int.TryParse(priceArray[1], out maxPrice))
{
    selectedItems.AddRange(productTypes
        .Where(x => x.HasValue("price") &&
        x.GetPropertyValue<int>("price") > minPrice &&
        x.GetPropertyValue<int>("price") < maxPrice &&
        x.HasValue("gender") &&
        (bothGender || x.GetPropertyValue<bool>("gender") == isMale)) // <-- changes here
        .Skip((page - 1) * pageSize).Take(pageSize));

//...
/。。。
var bothGender=真;
if(queryString.Get(“性别”)!=null)
{
isMale=bool.Parse(queryString.Get(“性别”));
bothGender=false;
}
if(priceArray.Count()==2&&int.TryParse(priceArray[0],out-minPrice)&&int.TryParse(priceArray[1],out-maxPrice))
{
选择EditEMS.AddRange(产品类型
其中(x=>x.HasValue(“价格”)&&
x、 GetPropertyValue(“价格”)>minPrice&&
x、 GetPropertyValue(“价格”)(bothGender | | x.GetPropertyValue(“性别”)==isMale))//这听起来像是一个枚举的工作,或者至少是一个可为null的bool。问题是我对这段代码还不是很熟悉。如果你有一个例子说明这是如何工作的,我会非常高兴的!你有3个案例-男和女-男-女。所以,你必须分别检查每个案例。虚假或真实的陈述不足以设置你的f过滤器。如果是,你只能按男性或女性过滤。想想看。对于稍微干净的代码,你可以将
两个过滤器
初始化为
true
,在
if
块内将其设置为
false
,然后跳过
else
。这就像一个符咒!我无意中检查了,没有选择价格范围。Th它很有魅力,谢谢你,托马斯,我今天学到了一些新东西。我在这里感谢你: