Пример #1
0
        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);
        }
Пример #2
0
        public TrieRepository(IStoreDb storeDb, ILogger logger)
            : base(storeDb, logger)
        {
            _storeDb = storeDb;
            _logger  = logger.ForContext("SourceContext", nameof(TrieRepository));

            SetTableName(StoreDb.TrieTable.ToString());
        }
Пример #3
0
        protected BaseController(IStoreDb data)
        {
            if (data == null)
            {
                throw new ArgumentException("An instance of IStoreDb is required to use this controller.", "data");
            }

            this.Data = data;
        }
Пример #4
0
        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;
        }
Пример #5
0
        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);
                }
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
 public CartController(IStoreDb data)
     : base(data)
 {
 }
Пример #8
0
 public BlockGraphRepository(IStoreDb storeDb, ILogger logger)
     : base(storeDb, logger)
 {
     SetTableName(StoreDb.BlockGraphTable.ToString());
 }
Пример #9
0
 public ProductsController(IStoreDb data)
     : base(data)
 {
 }
Пример #10
0
 public EditUserController(IStoreDb data)
     : base(data)
 {
 }
Пример #11
0
 public DataProtectionRepository(IStoreDb storeDb, ILogger logger)
     : base(storeDb, logger)
 {
     SetTableName(StoreDb.DataProtectionTable.ToString());
 }
Пример #12
0
 public HomeController(IStoreDb data)
     : base(data)
 {
 }
 public CategoryProductsController(IStoreDb data)
     : base(data)
 {
 }
Пример #14
0
 public CategoriesController(IStoreDb data)
     : base(data)
 {
 }
Пример #15
0
 public KeyImageRepository(IStoreDb storeDb, ILogger logger) : base(storeDb, logger)
 {
     _logger = logger.ForContext("SourceContext", nameof(KeyImageRepository));
     SetTableName(StoreDb.KeyImageTable.ToString());
 }