public GlobalPermissionForRole CheckExists(GlobalPermissionForRole permissionForRole)
        {
            if (permissionForRole.Permission != null && permissionForRole.MembershipRole != null)
            {
                return Get(permissionForRole.Permission.Id, permissionForRole.MembershipRole.Id);
            }

            return null;
        }
示例#2
0
        private static PermissionForRole MapGlobalPermission(GlobalPermissionForRole gp)
        {
            var pfr = new PermissionForRole
            {
                IsTicked       = gp.IsTicked,
                MembershipRole = gp.MembershipRole,
                Permission     = gp.Permission
            };

            return(pfr);
        }
        public void UpdateOrCreateNew(GlobalPermissionForRole globalPermissionForRole)
        {
            // Firstly see if this exists already
            var permission = CheckExists(globalPermissionForRole);

            // if it exists then just update it
            if (permission != null)
            {
                permission.IsTicked = globalPermissionForRole.IsTicked;
            }
            else
            {
                Add(globalPermissionForRole);
            }
        }
        public void UpdatePermission(AjaxEditPermissionViewModel ajaxEditPermissionViewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    if (Request.IsAjaxRequest())
                    {
                        if (ajaxEditPermissionViewModel.Category == Guid.Empty)
                        {
                            // If category is empty guid then this is a global permission

                            var gpr = new GlobalPermissionForRole
                            {
                                MembershipRole =
                                    _roleService.GetRole(ajaxEditPermissionViewModel.MembershipRole),
                                Permission =
                                    _permissionService.Get(ajaxEditPermissionViewModel.Permission),
                                IsTicked = ajaxEditPermissionViewModel.HasPermission
                            };
                            _globalPermissionForRoleService.UpdateOrCreateNew(gpr);
                        }
                        else
                        {
                            // We have a category so it's a category permission 

                            var mappedItem = new CategoryPermissionForRole
                            {
                                Category = _categoryService.Get(ajaxEditPermissionViewModel.Category),
                                MembershipRole =
                                    _roleService.GetRole(ajaxEditPermissionViewModel.MembershipRole),
                                Permission =
                                    _permissionService.Get(ajaxEditPermissionViewModel.Permission),
                                IsTicked = ajaxEditPermissionViewModel.HasPermission
                            };
                            _categoryPermissionForRoleService.UpdateOrCreateNew(mappedItem);   
                        }
                    }
                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    LoggingService.Error(ex);
                    throw;
                }
            }
        }
 public void Delete(GlobalPermissionForRole permissionForRole)
 {
     _context.GlobalPermissionForRole.Remove(permissionForRole);
 }
 public GlobalPermissionForRole Add(GlobalPermissionForRole permissionForRole)
 {
     return _context.GlobalPermissionForRole.Add(permissionForRole);
 }
 public void Delete(GlobalPermissionForRole permissionForRole)
 {
     _globalPermissionForRoleRepository.Delete(permissionForRole);
 }
 public void Add(GlobalPermissionForRole permissionForRole)
 {
     _globalPermissionForRoleRepository.Add(permissionForRole);
 }
 public void Add(GlobalPermissionForRole permissionForRole)
 {
     _context.GlobalPermissionForRole.Add(permissionForRole);
 }