Exemplo n.º 1
0
        private void Install()
        {
            //------ User -----//
            var user = Set <User>().FirstOrDefault();

            if (user == null)
            {
                using (var transaction = adapter.BeginTransaction())
                {
                    try
                    {
                        user = AddUser(new User()
                        {
                            Name     = "Admin",
                            Username = "******",
                            Password = "******",
                        });
                        //------ Module -----//
                        var module = AddAndSave(new Module()
                        {
                            Name = "Identity", Symbol = "Identity", Status = ModuleStatus.Active
                        });
                        //------ Role -----//
                        var role = Add(new Role()
                        {
                            ModuleId = module.Id, Name = "Admin", Symbol = "Admin", Status = RoleStatus.Active
                        });
                        //------ Permission -----//
                        Permission permission;
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "AuthenticatorApp", Symbol = "AuthenticatorApp"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "Claim", Symbol = "Claim"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "Event", Symbol = "Event"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "Module", Symbol = "Module"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "Permission", Symbol = "Permission"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "Position", Symbol = "Position"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "Question", Symbol = "Question"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "Role", Symbol = "Role"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "Social", Symbol = "Social"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "Token", Symbol = "Token"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        permission = AddAndSave(new Permission()
                        {
                            ModuleId = module.Id, Name = "User", Symbol = "User"
                        });
                        AddAndSave(new RolePermission(role.Id, permission.Id));
                        //------ UserRole -----//
                        AddAndSave(new UserRole(user.Id, role.Id));
                        AddToken(new Token()
                        {
                            UserId = user.Id
                        });
                        transaction.Commit();
                        installed = true;
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }