Exemple #1
0
        public void Setup(SysSetting setting) {
            var user = _membershipService.CreateUser(setting.AdminUsername, setting.AdminPassword);
            var permissions = _permissionProviders.Select(m => m.GetDefaultStereotypes()).Aggregate((f, s) => f.Concat(s).ToArray()).ToArray();

            var permissionGroups = permissions.GroupBy(m => m.Name);
            foreach (var permissionGroup in permissionGroups) {
                var role = new Role {
                    Name = permissionGroup.Key,
                    CreateAt = DateTime.UtcNow,
                    Description = permissionGroup.Key,
                    UpdateAt = DateTime.UtcNow
                };
                _roleService.Create(role);
                foreach (var permissionStereotype in permissionGroup.Select(m => m.Permissions).Aggregate((f, s) => f.Concat(s))) {
                    _rpRepository.Create(new RolePermission() {
                        Role_Id = role.Id,
                        Permission = permissionStereotype.Name
                    });
                }
                _accountRoleServicecs.AddUserRoles(user.Id, new[] { role.Id });
            }
            _siteService.AddOrUpdate(new SiteSetting {
                SiteName = setting.SiteName,
                SuperUser = setting.AdminUsername,
                PageSize = 20
            });
        }
Exemple #2
0
        public ActionResult EditorPost(RoleViewModel model) {
            Role role;
            var permissions = Request.Form["permissions"];
            if (model.Id > 0) {
                role = _roleService.Get(model.Id);
                _rpRepository.Delete(m => m.Role_Id == model.Id);
            } else {
                role = new Role() {
                    Name = model.Name,
                    Description = model.Description,
                    CreateAt = DateTime.UtcNow,
                    UpdateAt = DateTime.UtcNow
                };
                _roleService.Create(role);
            }
            if (!string.IsNullOrEmpty(permissions)) {
                var ps = permissions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var s in ps) {
                    if (_permissionProviders.Any(permissionProvider => permissionProvider.GetPermissions().Any(m => m.Name == s))) {
                        _rpRepository.Create(new RolePermission() {
                            Role_Id = role.Id,
                            Permission = s
                        });
                    }

                }
            }
            return RedirectToAction("Index");
        }