public IdentityResult RegisterAdminUser(UserDTO userModel)
        {
            IdentityResult result;

            DeliveryServiceUser userEntity = new DeliveryServiceUser
            {
                UserName = userModel.Username
            };

            using (var dbContext = new DeliveryServiceIdentityDbContext())
            {
                // create user
                var userManager = new DeliveryServiceUserManager(new UserStore <DeliveryServiceUser>(dbContext));
                result = userManager.Create(userEntity, userModel.Password);

                // add to role
                var roleManager = new RoleManager <DeliveryServiceRole>(new RoleStore <DeliveryServiceRole>(dbContext));
                DeliveryServiceRole adminRole = roleManager.FindByName("Administrator");

                if (adminRole == null)
                {
                    roleManager.Create(new DeliveryServiceRole {
                        Name = "Administrator"
                    });
                }

                userManager.AddToRole(userEntity.Id, "Administrator");
            }

            return(result);
        }
        public ICollection <string> GetUserRoles(string userId)
        {
            IList <string> userRoles = new List <string>();

            using (var dbContext = new DeliveryServiceIdentityDbContext())
            {
                var userManager = new DeliveryServiceUserManager(new UserStore <DeliveryServiceUser>(dbContext));
                userRoles = userManager.GetRoles(userId);
            }

            return(userRoles);
        }
        public IdentityUser FindUser(string username, string password)
        {
            IdentityUser result;

            using (var dbContext = new DeliveryServiceIdentityDbContext())
            {
                var userManager = new DeliveryServiceUserManager(new UserStore <DeliveryServiceUser>(dbContext));
                result = userManager.Find(username, password);
            }

            return(result);
        }