我有一系列价格的产品。我希望根据用户组显示相应的价格。
到目前为止,我创建了描述这些组的角色
- 行政
- 用户价格A
- 用户价格B
- 用户价格C
我想以某种方式获得当前用户角色。
像这样的东西:
public decimal Price {
get
{
var price = Prices.First(p => p.PriceType.Name == Something.CurentUser.Role);
return price;
}
}
我有一系列价格的产品。我希望根据用户组显示相应的价格。
到目前为止,我创建了描述这些组的角色
我想以某种方式获得当前用户角色。
像这样的东西:
public decimal Price {
get
{
var price = Prices.First(p => p.PriceType.Name == Something.CurentUser.Role);
return price;
}
}
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")) {
// ...
}
你不能那样做,因为一个用户可以有多个角色,但你可以这样做
Price.Where(p=> Membership.GetRoles().Contains(p.PriceType.Name))在这部手机上打字不好玩...抱歉简洁