Example #1
0
        /// <summary>
        /// 增加数据角色映射信息
        /// </summary>
        /// <param name="dto">数据角色映射信息DTO</param>
        /// <returns>业务操作结果</returns>
        public virtual async Task <OperationResult> AddEntityRoleMapAsync(TEntityRoleMapDto dto)
        {
            dto.CheckNotNull("dto");
            if (await EntityRoleMapRepository.CheckExistsAsync(m => m.EntityInfo.Id.Equals(dto.EntityInfoId) && m.Role.Id.Equals(dto.RoleId)))
            {
                return(new OperationResult(OperationResultType.Error, "指定数据与角色的数据角色映射信息已存在"));
            }
            TEntityInfo entityInfo = await EntityInfoRepository.GetByKeyAsync(dto.EntityInfoId);

            if (entityInfo == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的数据实体信息不存在"));
            }
            TRole role = await RoleRepository.GetByKeyAsync(dto.RoleId);

            if (role == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的角色信息不存在"));
            }
            TEntityRoleMap map = dto.MapTo <TEntityRoleMap>();

            map.EntityInfo = entityInfo;
            map.Role       = role;
            if (dto.FilterGroup != null)
            {
                map.FilterGroupJson = dto.FilterGroup.ToJsonString();
            }
            return(await EntityRoleMapRepository.InsertAsync(map) > 0
                ? new OperationResult(OperationResultType.Success, "数据角色映射信息添加成功")
                : OperationResult.NoChanged);
        }
Example #2
0
        /// <summary>
        /// 增加数据角色映射信息
        /// </summary>
        /// <param name="dto">数据角色映射信息DTO</param>
        /// <returns>业务操作结果</returns>
        public virtual async Task <OperationResult> CreateEntityRoleMapAsync(TEntityRoleMapInputDto dto)
        {
            dto.CheckNotNull("dto");
            if (await EntityRoleMapRepository.CheckExistsAsync(m => m.EntityInfo.Id.Equals(dto.EntityInfoId) && m.Role.Id.Equals(dto.RoleId)))
            {
                return(OperationResult.Success);
            }
            TEntityInfo entityInfo = await EntityInfoRepository.GetByKeyAsync(dto.EntityInfoId);

            if (entityInfo == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的数据实体信息不存在"));
            }
            TRole role = await RoleRepository.GetByKeyAsync(dto.RoleId);

            if (role == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的角色信息不存在"));
            }
            TEntityRoleMap map = dto.MapTo <TEntityRoleMap>();

            map.EntityInfo = entityInfo;
            map.Role       = role;
            if (dto.FilterGroup != null)
            {
                map.FilterGroupJson = dto.FilterGroup.ToJsonString();
            }
            return(await EntityRoleMapRepository.InsertAsync(map) > 0
                ? new OperationResult(OperationResultType.Success, "角色“{0}”与数据“{1}”映射信息创建成功".FormatWith(role.Name, entityInfo.Name))
                : OperationResult.NoChanged);
        }