Example #1
0
        public static int CreateGroupsUsers()
        {
            CSystemUserGroup AdminGroup = new CSystemUserGroup(DatabaseContext)
            {
                FullDescription = "Группа администраторов",
                ShortDescription = "Группа администраторов",
                Name = "Администраторы",
                ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_GROUP_ADMINISTRATORS_ID),
                Key = CEmbeddedSecurityConsts.CONST_USER_GROUP_ADMINISTRATORS_KEY,
                ModificatonDate = DateTime.Now,                
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = true
            };
            var R = AdminGroup.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CSystemUserGroup ModeratorsGroup = new CSystemUserGroup(DatabaseContext)
            {
                FullDescription = "Группа модераторов",
                ShortDescription = "Группа модераторов",
                Name = "Модераторы",
                ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_ID),
                Key = CEmbeddedSecurityConsts.CONST_USER_GROUP_MODERATORS_KEY,
                ModificatonDate = DateTime.Now,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = true
            };
            R = AdminGroup.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CSystemUserGroup UsersGroup = new CSystemUserGroup(DatabaseContext)
            {
                FullDescription = "Группа пользователей",
                ShortDescription = "Группа пользователей",
                Name = "Пользователи",
                ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_GROUP_USERS_ID),
                Key = CEmbeddedSecurityConsts.CONST_USER_GROUP_USERS_KEY,
                ModificatonDate = DateTime.Now,
                Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY,
                Status = EnMetaobjectStatus.EEnabled,
                System = true
            };
            R = AdminGroup.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            CSystemUser AdminUser = new CSystemUser(DatabaseContext)
            {
                ID = Guid.Parse(CEmbeddedSecurityConsts.CONST_USER_ADMINISTRATOR_ID),
                Key = CEmbeddedSecurityConsts.CONST_USER_ADMINISTRATOR_KEY,
                ShortDescription = "Главный администратор системы",
                Email = "*****@*****.**",
                EnterpriseType = -1,
                FirstName = "Administrator",
                SecondName = "",
                Surname = "",
                Login = "******",
                Name = "Администратор",
                MobilePhone = "89028087122",
                HomePhone = "",
                WorkPhone = "",
                Passhash = CSecurityHelper.sGeneratePasshash("Administrator", "q"),
                ModificatonDate = DateTime.Now,                
                Parent = CEmbeddedSecurityConsts.CONST_USER_GROUP_ADMINISTRATORS_KEY,                
                Status = EnMetaobjectStatus.EEnabled,               
                System = true                
            };
            R = AdminUser.ObjectInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;

            cMenu.Metaobjects.Linq.CMetaobjectLink Link = new Metaobjects.Linq.CMetaobjectLink()
            {
                LinkedObjectKey = AdminUser.Key,
                LinkType = EnMetaobjectLinkType.ESecurity,
                LinkValue = 1,
                SourceObjectKey = AdminGroup.Key
            };
            R = Link.LinkInsert(DatabaseContext);
            if (R != CErrors.ERR_SUC)
                return R;
            try
            { DatabaseContext.SubmitChanges(); }
            catch (Exception Exception)
            {
                throw new Exception(Exception.Message);
                return CErrors.ERR_DB_INSERT_OBJECT;
            }            

            return CErrors.ERR_SUC;
        }