Пример #1
0
        public Framework.Common.Service.Message.ResponseDto GrantRolePermission(Common.DTO.RoleDto role, int permissionId)
        {
            ResponseDto response   = new ResponseDto();
            var         permission = this.GetSingle(it => it.PermissionId == permissionId);

            if (permission != null)
            {
                PermissionToRoleTDataAccess pda = new PermissionToRoleTDataAccess();
                var ptorole = pda.GetSingle(it => it.PermissionId == permissionId && it.RoleId == role.RoleId);
                if (ptorole != null && ptorole.PermisssionAccess > 0)
                {
                    response.Response.AddBusinessException("بدلیل وجود محدودیت ایجاد چنین دسترسی غر مجاز می باشد!", BusinessExceptionEnum.Operational);
                }
                else
                {
                    PermissionToRoleTDataAccess perToUserDa = new PermissionToRoleTDataAccess();
                    PermissionToRoleDto         perToUser   = new PermissionToRoleDto()
                    {
                        RoleId       = role.RoleId,
                        PermissionId = permissionId
                    };
                    perToUserDa.Insert(perToUser);
                }
            }
            else
            {
                response.Response.AddBusinessException("چنین دسترسی وجود ندارد", BusinessExceptionEnum.Operational);
            }
            return(response);
        }
Пример #2
0
        public ResponseDtoContainer ChangeRolePermissons(List <PermissionDto> permissions, int roleId)
        {
            ResponseDtoContainer        container  = new ResponseDtoContainer();
            List <PermissionToRoleDto>  updateList = new List <PermissionToRoleDto>();
            PermissionToRoleTDataAccess puDa       = new PermissionToRoleTDataAccess();

            foreach (var item in permissions)
            {
                var pu = puDa.GetSingle(it => it.PermissionId == item.PermissionId && it.RoleId == roleId);
                if (pu != null)
                {
                    if (item.AccessType == Common.Enums.AccessType.None)
                    {
                        puDa.Delete(pu);
                    }
                    else
                    {
                        pu.PermisssionAccess = (short)item.AccessType;
                        updateList.Add(pu);
                    }
                    ResponseDto response = new ResponseDto(pu.Response);
                    container.ResponseDtoList.Add(response);
                }
                else if (pu == null && (item.AccessType == Common.Enums.AccessType.Access || item.AccessType == Common.Enums.AccessType.Deny))
                {
                    PermissionToRoleDto newPermission = new PermissionToRoleDto()
                    {
                        PermissionId      = item.PermissionId,
                        RoleId            = roleId,
                        PermisssionAccess = (short)item.AccessType
                    };
                    puDa.Insert(newPermission);
                    ResponseDto response = new ResponseDto(newPermission.Response);
                    container.ResponseDtoList.Add(response);
                }
                else
                {
                    item.Response.AddBusinessException("موجود نیست", BusinessExceptionEnum.Operational);
                }
            }
            puDa.Update(updateList);
            return(container);
        }