示例#1
0
        public static void UserAdd()
        {
            UserArgs args = (UserArgs)PSCDialog.DataShare;
            User     user = ((UserArgs)PSCDialog.DataShare).User;
            CustomMembershipProvider customMembership = new CustomMembershipProvider();

            user.Password = customMembership.TransformPassword(user.Password);
            bool validate = customMembership.ValidateUserNameAndEmail(user);

            if (user.Name.Trim() == "" || validate == false)
            {
                return;
            }
            UserList.AddDB(user);
            // roles of user
            UserInRoleCollection userInRoleCollection = new UserInRoleCollection();
            UserInRole           userInRole           = null;
            string subdomain = SessionHelper.GetSession(SessionKey.SubDomain);

            if (!(subdomain == Guid.Empty.ToString())) // thuoc it nhat 1 subdomain
            {
                UserInSubDomainCollection userInSubDomainCollection = new UserInSubDomainCollection();
                UserInSubDomain           userInSubDomain           = new UserInSubDomain();
                userInSubDomain.UserId      = user.Id;
                userInSubDomain.SubDomainId = new Guid(subdomain);
                userInSubDomainCollection.AddDB(userInSubDomain);
                // administrators
                if (args.IsAdministrator)
                {
                    Role roleAdministrator = RoleCollection.GetRoleCollection()
                                             .Single(r => r.Name == System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"]);
                    userInRole        = new UserInRole();
                    userInRole.RoleId = roleAdministrator.Id;
                    userInRole.UserId = user.Id;
                    userInRoleCollection.AddDB(userInRole);
                }
            }
            else // subdomain : all
            {
                // administrators
                if (args.IsAdministrator)
                {
                    Role roleAdministrator = RoleCollection.GetRoleCollection().Single(r => r.Name == System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"]);
                    userInRole        = new UserInRole();
                    userInRole.RoleId = roleAdministrator.Id;
                    userInRole.UserId = user.Id;
                    userInRoleCollection.AddDB(userInRole);
                }
            }
            DataStatic["DisplayUserList"] = null;
        }