private IList <Role> GetUserRoles(ApplicationUser user, IStoreDb db) { // Create user manager var userManager = Request .GetOwinContext() .GetUserManager <ApplicationUserManager>(); // Get all application roles var roles = db.IdentityRoles.All() .Select(r => r.Name) .OrderBy(r => r) .ToList(); // For each application role, check if the user has it var userRoles = new List <Role>(); foreach (var roleName in roles) { var role = new Role { Name = roleName }; if (userManager.IsInRole(user.Id, roleName)) { role.IsSelected = true; } userRoles.Add(role); } // Return a list with all roles return(userRoles); }
public TrieRepository(IStoreDb storeDb, ILogger logger) : base(storeDb, logger) { _storeDb = storeDb; _logger = logger.ForContext("SourceContext", nameof(TrieRepository)); SetTableName(StoreDb.TrieTable.ToString()); }
protected BaseController(IStoreDb data) { if (data == null) { throw new ArgumentException("An instance of IStoreDb is required to use this controller.", "data"); } this.Data = data; }
protected BaseController(IStoreDb data, ApplicationUser userProfile) : this(data) { if (userProfile == null) { throw new ArgumentException("An instance of ApplicationUser is required to use this controller.", "data"); } this.UserProfile = userProfile; }
private void SetUserRoles(EditUserViewModel viewModel, ApplicationUser user, IStoreDb Data) { var userManager = HttpContext .GetOwinContext() .GetUserManager <ApplicationUserManager>(); foreach (var role in viewModel.Roles) { if (role.IsSelected && !userManager.IsInRole(user.Id, role.Name)) { userManager.AddToRole(user.Id, role.Name); } else if (!role.IsSelected && userManager.IsInRole(user.Id, role.Name)) { userManager.RemoveFromRole(user.Id, role.Name); } } }
private HashSet <string> GetAdminUserNames(List <ApplicationUser> users, IStoreDb data) { // Create user manager var userManager = Request .GetOwinContext() .GetUserManager <ApplicationUserManager>(); var admins = new HashSet <string>(); foreach (var user in users) { if (userManager.IsInRole(user.Id, "Admin")) { admins.Add(user.UserName); } } return(admins); }
public CartController(IStoreDb data) : base(data) { }
public BlockGraphRepository(IStoreDb storeDb, ILogger logger) : base(storeDb, logger) { SetTableName(StoreDb.BlockGraphTable.ToString()); }
public ProductsController(IStoreDb data) : base(data) { }
public EditUserController(IStoreDb data) : base(data) { }
public DataProtectionRepository(IStoreDb storeDb, ILogger logger) : base(storeDb, logger) { SetTableName(StoreDb.DataProtectionTable.ToString()); }
public HomeController(IStoreDb data) : base(data) { }
public CategoryProductsController(IStoreDb data) : base(data) { }
public CategoriesController(IStoreDb data) : base(data) { }
public KeyImageRepository(IStoreDb storeDb, ILogger logger) : base(storeDb, logger) { _logger = logger.ForContext("SourceContext", nameof(KeyImageRepository)); SetTableName(StoreDb.KeyImageTable.ToString()); }