1

I have a product with array of prices. I want that based on the user group the corresponding price will be displayed.

As far i created roles that are describing these groups

  1. Admin
  2. UserPriceA
  3. UserPriceB
  4. UserPriceC

I would like somehow to get current users role.

Something like this:

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

You can't do it quite like that because a user can have multiple roles but you could do

Prices.Where( p=> Membership.GetRoles().Contains(p.PriceType.Name))
typing on this phone isn't fun... Sorry for the brevity

于 2011-05-15T06:21:19.153 に答える