Exemple #1
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");
        }
Exemple #2
0
 public ActionResult Editor(int? id) {
     var model = new RoleViewModel();
     var permissions = new List<Permission>();
     foreach (var permissionProvider in _permissionProviders) {
         permissions.AddRange(permissionProvider.GetPermissions());
     }
     if (id.HasValue) {
         var role = _roleService.Get(id.Value);
         if (role != null) {
             model = new RoleViewModel {
                 Id = role.Id,
                 Name = role.Name,
                 Description = role.Description,
                 RolePermission = _rpRepository.All.Where(m => m.Role_Id == id.Value).Select(m => m.Permission).ToArray(),
             };
         }
     }
     model.Permisions = permissions;
     return View(model);
 }