protected void CreateRolesAndUsersForTask()
        {
            var roles = new [] { "Employees", "USA", "Managers", "Ukraine", "Developers", "Main Office" };

            roles.ForEach(role => IdentityRepository.AddRole(role));
            IdentityRepository.AddChildrenRoles("Employees", new List <string> {
                "USA", "Managers", "Ukraine", "Developers"
            });
            IdentityRepository.AddChildrenRoles("Ukraine", new List <string> {
                "Main Office"
            });
            IdentityRepository.AddChildrenRoles("Developers", new List <string> {
                "Main Office"
            });

            CreateUserForTask("O. Cole", "*****@*****.**");
            CreateUserForTask("J. Shane", "*****@*****.**");
            CreateUserForTask("V. Petrov", "*****@*****.**");
            CreateUserForTask("M. Popov", "*****@*****.**");

            IdentityRepository.AddUserInRoles("O. Cole", new [] { "USA" });
            IdentityRepository.AddUserInRoles("J. Shane", new[] { "USA", "Managers" });
            IdentityRepository.AddUserInRoles("V. Petrov", new[] { "Main Office" });
            IdentityRepository.AddUserInRoles("M. Popov", new[] { "Main Office" });
        }
Beispiel #2
0
        public BaseResponse CreateUser(CreateUserRequest request)
        {
            var accountModel = new AccountModel
            {
                IsActivate  = true,
                AccountName = request.UserName,
                Description = request.Description,
                Email       = request.Email,
                Note        = request.Note
            };
            var baseRoles = (request.BaseRoles ?? Enumerable.Empty <string>()).ToArray();

            IdentityRepository.CreateUser(accountModel, "!@#$%^&*()");
            IdentityRepository.AddUserInRoles(request.UserName, baseRoles);
            return(BaseResponse.Ok());
        }
Beispiel #3
0
        public BaseResponse UpdateUser(CreateUserRequest request)
        {
            var accountModel = new AccountModel
            {
                IsActivate  = true,
                AccountName = request.UserName,
                Description = request.Description,
                Email       = request.Email,
                Note        = request.Note
            };

            IdentityRepository.UpdateUser(accountModel);
            var baseRoles = (request.BaseRoles ?? Enumerable.Empty <string>()).ToArray();
            var userRoles = IdentityRepository.GetRolesForUser(request.UserName);

            IdentityRepository.RemoveUserInRoles(request.UserName, userRoles.ToArray());
            IdentityRepository.AddUserInRoles(request.UserName, baseRoles);
            return(BaseResponse.Ok());
        }
Beispiel #4
0
 public BaseResponse AddUserInRoles(AddUserInRolesRequest request)
 {
     IdentityRepository.AddUserInRoles(request.UserName, request.Roles);
     return(BaseResponse.Ok());
 }