1

我有一系列价格的产品。我希望根据用户组显示相应的价格。

到目前为止,我创建了描述这些组的角色

  1. 行政
  2. 用户价格A
  3. 用户价格B
  4. 用户价格C

我想以某种方式获得当前用户角色。

像这样的东西:

public decimal Price {
    get
    {
        var price = Prices.First(p => p.PriceType.Name == Something.CurentUser.Role);
        return price; 
    }
}
4

2 回答 2

1

You can write a conditional statement based on the name of each role. Based on if the user is a member of the role, execute a different LINQ statement.

if (User.IsInRole("Admin")) {
    // ...
}
else if (User.IsInRole("UserPriceA")) {
   // ...
}
else if (User.IsInRole("UserPriceB")) {
   // ...
}
else if (User.IsInRole("UserPriceC")) {
   // ...
}
于 2011-05-15T06:18:39.013 回答
1

你不能那样做,因为一个用户可以有多个角色,但你可以这样做

Price.Where(p=> Membership.GetRoles().Contains(p.PriceType.Name))
在这部手机上打字不好玩...抱歉简洁

于 2011-05-15T06:21:19.153 回答