public async Task <RolePermissionResponse> GetRolesPerminssion(RolePermissionRequest rolePermissionRequest)
        {
            RolePermissionResponse rolePermission = new RolePermissionResponse();

            try
            {
                rolePermission = (from rp in ObjContext.RolePermissions
                                  where rp.RoleId == rolePermissionRequest.RoleId && rp.ScreenId == rolePermissionRequest.ScreenId &&
                                  rp.PermissionId == rolePermissionRequest.PermissionId && rp.IsDeleted == false
                                  select new RolePermissionResponse
                {
                    rolePermissionId = rp.RolePermissionId,
                    RoleId = rp.RoleId,
                    ScreenId = rp.ScreenId,
                    PermissionId = rp.PermissionId,
                    CreatedOn = rp.CreatedOn,
                    CreatedBy = Convert.ToInt32(rp.CreatedBy)
                }).FirstOrDefault();
                return(rolePermission);
            }
            catch (System.Exception ex)
            {
                var msg = ex.Message;
                throw;
            }
        }
Ejemplo n.º 2
0
        public IActionResult Get(int id)
        {
            RolePermission rolePermission = this._rolePermissionService.Get(id);

            RolePermissionResponse rolePermissionResponse = AutoMap.Map <RolePermission, RolePermissionResponse>(rolePermission);

            return(Ok(new BaseResponse <RolePermissionResponse>(rolePermissionResponse)));
        }
Ejemplo n.º 3
0
        public IActionResult Modify([FromBody] RolePermissionRequest rolePermissionRequest)
        {
            RolePermission rolePermission = AutoMap.Map <RolePermissionRequest, RolePermission>(rolePermissionRequest);

            this._rolePermissionService.Modify(rolePermission.Identity, rolePermission);

            RolePermissionResponse rolePermissionResponse = AutoMap.Map <RolePermissionRequest, RolePermissionResponse>(rolePermissionRequest);

            return(Ok(new BaseResponse <RolePermissionResponse>(rolePermissionResponse)));
        }
Ejemplo n.º 4
0
        public IHttpActionResult GetRolePermission(string Guid)
        {
            RolePermissionResponse response = new RolePermissionResponse()
            {
                IsSuccess        = true,
                MessageCode      = (int)ApiBaseErrorCode.API_SUCCESS,
                MessageContent   = ApiBaseErrorCode.API_SUCCESS.ToString(),
                OpenUpMenuSerial = new List <string>()
            };

            if (string.IsNullOrWhiteSpace(Guid))
            {
                response.IsSuccess      = false;
                response.MessageCode    = (int)ApiBaseErrorCode.API_PARAM_ERROR;
                response.MessageContent = "角色标识不能为空,请检查";
                return(Ok(response));
            }

            RolePermissionModel rolemodel = rolemanager.GetRole(Guid);

            if (rolemodel != null)
            {
                string privilegeStr = rolemodel.ContentDetial;
                for (int i = 1; i <= privilegeStr.Length / 4; i++)
                {
                    try
                    {
                        string flag       = privilegeStr.Substring(i * 4 - 1, 1);
                        string menuserial = privilegeStr.Substring((i - 1) * 4, 3);
                        if (flag == "1")
                        {
                            response.OpenUpMenuSerial.Add(menuserial);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogFatal(LoggerLogicEnum.Interface, "", "", "", rolemodel.ProjectGuid, "获取角色权限时发生异常", ex.ToString());
                    }
                }

                if (!string.IsNullOrEmpty(rolemodel.ParkingCodeList))
                {
                    response.ParkingCodeList = rolemodel.ParkingCodeList.Split(',').ToList();
                }

                response.IsAdmin = rolemodel.IsAdmin;
            }
            else
            {
                response.IsSuccess      = false;
                response.MessageCode    = (int)ApiPersonnelErrorCode.API_DATA_NULL_ERROR;
                response.MessageContent = ApiPersonnelErrorCode.API_DATA_NULL_ERROR.ToString();
            }
            return(Ok(response));
        }
Ejemplo n.º 5
0
        public RolePermissionResponse LoadRoleActions(int roleId, int?drugStoreId)
        {
            var result = new RolePermissionResponse()
            {
                RoleId                 = roleId,
                RoleName               = string.Empty,
                PermittedResources     = new List <ResourcePermission>(),
                NonePermittedResources = new List <ResourcePermission>()
            };
            var role = _dataFilterService.GetValidRoles().FirstOrDefault(i => i.RoleId == roleId);

            if (role == null)
            {
                return(result);
            }

            var actions      = HttpActionEnumHelper.GetAllActions();
            var rolePerRepo  = IoC.Container.Resolve <BaseRepositoryV2 <MedDbContext, Med.Entity.Admin.RolePermission> >();
            var rolePermises = rolePerRepo.GetAll().Where(i => i.RoleId == roleId);

            if (drugStoreId > 0 && rolePermises.Any(i => i.DrugStoreID == drugStoreId))
            {
                rolePermises = rolePermises.Where(i => i.DrugStoreID == drugStoreId);
            }
            var permittedResources = rolePermises
                                     .Select(i => new ResourcePermission()
            {
                PermissionId = i.PermissionId,
                ResourceId   = i.ResourceId
            }).ToList();

            permittedResources.ForEach(i =>
            {
                i.ResourceName = actions[i.ResourceId].ActionName;
            });
            var permittedResourceIds  = permittedResources.Select(i => i.ResourceId).ToList();
            var nonPermittedResources = actions.Where(i => !permittedResourceIds.Contains(i.Key))
                                        .Select(i => new ResourcePermission()
            {
                PermissionId = (int)PermissionType.None,
                ResourceId   = i.Key,
                ResourceName = i.Value.ActionName
            }).ToList();

            result.RoleName               = role.RoleName;
            result.PermittedResources     = permittedResources;
            result.NonePermittedResources = nonPermittedResources;

            return(result);
        }