Пример #1
0
        public void CanCreateUserAndRole()
        {
            IRepository<Role> repoA = new RoleRepository();
            Role role1 = new Role();
            role1.Name = "PruebaRol1";
            role1.Description = "Prueba descriptiva rol 1";
            Role role2 = new Role();
            role2.Name = "PruebaRol2";
            role2.Description = "Prueba descriptiva rol 2";

            repoA.Save(role1);
            repoA.Save(role2);

            IRepository<User> repoB = new UserRepository();
            User user1 = new User();
            user1.DocumentId = 11111;
            user1.LoginEmail = "*****@*****.**";
            user1.FirstName = "Usuario prueba nombre 1";
            user1.MiddleName = "Usuario prueba nombre 2";
            user1.LastName1 = "Usuario prueba apellido 1";
            user1.LastName2 = "Usuario prueba apellido 2";
            user1.PhoneNumber = "457-4334(90)";
            user1.IsActive = true;
            user1.Password = "******";

            UserRole userRole1 = new UserRole();
            userRole1.Role = role1;
            userRole1.User = user1;
            UserRole userRole2 = new UserRole();
            userRole2.Role = role2;
            userRole2.User = user1;

            user1.Roles.Add(userRole1);
            user1.Roles.Add(userRole2);

            repoB.Save(user1);
        }
Пример #2
0
 private void AddRolesInstances(User user, FormCollection form)
 {
     var roles = form["RoleIds"].Replace(",", "");
     foreach (Object role in roles)
     {
         UserRole userRole = new UserRole();
         userRole.Role = dbR.GetById(Convert.ToInt32(role.ToString()));
         userRole.User = user;
         user.Roles.Add(userRole);
     }
 }