Beispiel #1
0
        public SubToSuperRelationshipDTO ToSubToSuperRelationshipDTO(SubToSuperRelationshipType item, RelationshipDTO baseRelationship = null)
        {
            BizRelationship biz = new MyModelManager.BizRelationship();

            if (baseRelationship == null)
            {
                baseRelationship = biz.ToRelationshipDTO(item.RelationshipType.Relationship);
            }
            Mapper.Initialize(cfg => cfg.CreateMap <RelationshipDTO, SubToSuperRelationshipDTO>());
            var result = AutoMapper.Mapper.Map <RelationshipDTO, SubToSuperRelationshipDTO>(baseRelationship);

            result.ISARelationship = ToISARelationshipDTO(item.ISARelationship);
            //  result.DeterminerColumnValue = item.RelationshipType.Relationship.Relationship2.RelationshipType.SuperToSubRelationshipType.DeterminerColumnValue;
            //  result.DeterminerColumnID = item.RelationshipType.Relationship.Relationship2.RelationshipType.SuperToSubRelationshipType.DeterminerColumnID ?? 0;

            foreach (var val in item.RelationshipType.Relationship.Relationship2.RelationshipType.SuperToSubRelationshipType.SuperToSubDeterminerValue)
            {
                result.DeterminerColumnValues.Add(new SuperToSubDeterminerValueDTO()
                {
                    ID = val.ID, Value = val.DeterminerValue
                });
            }
            if (item.RelationshipType.Relationship.Relationship2.RelationshipType.SuperToSubRelationshipType.SuperEntityDeterminerColumnID != null)
            {
                BizColumn bizColumn = new BizColumn();
                result.SuperEntityDeterminerColumnID = item.RelationshipType.Relationship.Relationship2.RelationshipType.SuperToSubRelationshipType.SuperEntityDeterminerColumnID.Value;
                result.SuperEntityDeterminerColumn   = bizColumn.GetColumn(result.SuperEntityDeterminerColumnID, true);
            }
            return(result);
        }
        private List <DatabaseFunction_Entity_ColumnDTO> ToDatabaseFunctionEntityColumnsDTO(DatabaseFunction_TableDrivedEntity cItem)
        {
            BizColumn bizColumn = new BizColumn();
            List <DatabaseFunction_Entity_ColumnDTO> result = new List <DatabaseFunction_Entity_ColumnDTO>();

            foreach (var column in cItem.DatabaseFunction_TableDrivedEntity_Columns)
            {
                var item = new DatabaseFunction_Entity_ColumnDTO();
                item.ID = column.ID;
                item.DatabaseFunctionParameterID = column.DatabaseFunctionParameterID;
                item.DatabaseFunction_EntityID   = column.DatabaseFunction_TableDrivedEntityID;
                if (column.ColumnID != null)
                {
                    item.ColumnID   = column.ColumnID.Value;
                    item.ColumnName = column.Column.Name;
                }
                if (column.FixedParamID != null)
                {
                    item.FixedParam = (Enum_FixedParam)column.FixedParamID;
                }
                item.FunctionColumnDotNetType = bizColumn.GetColumnDotNetType(column.DatabaseFunctionParameter.DataType, false);
                item.FunctionColumnParamName  = column.DatabaseFunctionParameter.ParamName;
                result.Add(item);
            }
            return(result);
        }
        private Type GetReturnType(DatabaseFunction cItem)
        {
            //اینجا میتوان برای استورد پروسیجر ها با یک خصوصیت تعیین کرد که کدوم پارامتر خروجی اصلی است
            BizColumn bizColumn = new BizColumn();
            DatabaseFunctionParameter parameter = null;
            var output = (short)Enum_DatabaseFunctionParameterType.Output;

            parameter = cItem.DatabaseFunctionParameter.FirstOrDefault(x => x.InputOutput == output);
            if (parameter != null)
            {
                return(bizColumn.GetColumnDotNetType(parameter.DataType, false));
            }
            else
            {
                output    = (short)Enum_DatabaseFunctionParameterType.InputOutput;
                parameter = cItem.DatabaseFunctionParameter.FirstOrDefault(x => x.InputOutput == output);
                if (parameter != null)
                {
                    return(bizColumn.GetColumnDotNetType(parameter.DataType, false));
                }
                else
                {
                    output    = (short)Enum_DatabaseFunctionParameterType.ReturnValue;
                    parameter = cItem.DatabaseFunctionParameter.FirstOrDefault(x => x.InputOutput == output);
                    if (parameter != null)
                    {
                        return(bizColumn.GetColumnDotNetType(parameter.DataType, false));
                    }
                }
            }
            return(null);
        }
        public DatabaseFunctionDTO ToDatabaseFunctionDTO(DatabaseFunction cItem, bool withColumns)
        {
            BizColumn bizColumn = new BizColumn();
            var       result    = new DatabaseFunctionDTO();

            result.ID   = cItem.ID;
            result.Name = cItem.FunctionName;
            //result.Catalog = cItem.Catalog;
            result.SchemaID      = cItem.DBSchemaID;
            result.DatabaseID    = cItem.DBSchema.DatabaseInformationID;
            result.RelatedSchema = cItem.DBSchema.Name;

            //result.ReturnType = cItem.ReturnType;
            //if (cItem.ValueCustomType != null)
            //    result.ValueCustomType = (ValueCustomType)cItem.ValueCustomType;
            result.Type = (Enum_DatabaseFunctionType)cItem.Type;

            result.Title  = cItem.Title;
            result.Enable = cItem.Enable;
            //if (result.Title == null)
            //{
            //    result.Title = cItem.FunctionName;
            //}
            if (withColumns)
            {
                result.DatabaseFunctionParameter = ToDatabaseFunctionParameterDTO(cItem);
            }
            //    if (result.Type == Enum_DatabaseFunctionType.Function)

            result.ReturnDotNetType = GetReturnType(cItem);

            return(result);
        }
        private bool ImposeSecurity(DR_Requester requester, EntitySearchDTO entitySearchDTO, TableDrivedEntity entity)
        {
            BizColumn bizColumn = new BizColumn();

            if (requester.SkipSecurity)
            {
                return(true);
            }

            if (!bizTableDrivedEntity.DataIsAccessable(requester, entity))
            {
                return(false);
            }
            var permission = bizTableDrivedEntity.GetEntityAssignedPermissions(requester, entitySearchDTO.TableDrivedEntityID, true);

            List <EntitySearchColumnsDTO> removeList = new List <ModelEntites.EntitySearchColumnsDTO>();

            foreach (var columnGroup in entitySearchDTO.EntitySearchAllColumns.GroupBy(x => x.RelationshipTailID))
            {
                bool pathPermission = true;
                if (columnGroup.Key == 0)
                {
                    pathPermission = true;
                }
                else
                {
                    var relationshipTail = columnGroup.First(x => x.RelationshipTailID == columnGroup.Key).RelationshipTail;
                    pathPermission = bizEntityRelationshipTail.DataIsAccessable(requester, relationshipTail);
                }
                if (!pathPermission)
                {
                    foreach (var column in columnGroup)
                    {
                        removeList.Add(column);
                    }
                }
                else
                {
                    foreach (var column in columnGroup)
                    {
                        if (column.ColumnID != 0 && !bizColumn.DataIsAccessable(requester, column.ColumnID))
                        {
                            removeList.Add(column);
                        }
                    }
                }
            }
            foreach (var remove in removeList)
            {
                entitySearchDTO.EntitySearchAllColumns.Remove(remove);
            }
            return(true);
        }
        public EntityStateConditionDTO ToEntityStateConditionDTO(DR_Requester requester, TableDrivedEntityStateCondition item, bool withDetails)
        {
            var result = new EntityStateConditionDTO();

            result.ID        = item.ID;
            result.FormulaID = item.FormulaID ?? 0;
            if (result.FormulaID != 0 && withDetails)
            {  //??با جزئیات؟؟........................................................................
                var bizFormula = new BizFormula();
                result.Formula = bizFormula.GetFormula(requester, item.FormulaID.Value, withDetails);
            }
            result.ColumnID = item.ColumnID ?? 0;
            if (item.Column != null)
            {
                BizColumn bizColumn = new BizColumn();
                result.Column = bizColumn.ToColumnDTO(item.Column, true);
            }
            result.Title = item.Title;
            result.RelationshipTailID = item.EntityRelationshipTailID ?? 0;
            if (item.EntityRelationshipTail != null)
            {
                BizEntityRelationshipTail bizEntityRelationshipTail = new BizEntityRelationshipTail();
                result.RelationshipTail = bizEntityRelationshipTail.ToEntityRelationshipTailDTO(item.EntityRelationshipTail);
            }
            if (item.ValueOpoerator != null)
            {
                result.EntityStateOperator = (Enum_EntityStateOperator)item.ValueOpoerator;
            }

            foreach (var valItem in item.TableDrivedEntityStateConditionValues)
            {
                result.Values.Add(new ModelEntites.EntityStateValueDTO()
                {
                    Value = valItem.Value, SecurityReservedValue = valItem.ReservedValue == null ? SecurityReservedValue.None : (SecurityReservedValue)valItem.ReservedValue
                });
            }

            foreach (var valItem in item.TableDrivedEntityStateConditionSecuritySubject)
            {
                result.SecuritySubjects.Add(new ChildSecuritySubjectDTO {
                    SecuritySubjectID = valItem.SecuritySubjectID
                });                                                                                                        //, SecuritySubjectOperator = (Enum_SecuritySubjectOperator)valItem.SecuritySubjectOperator });
            }
            if (item.SecuritySubjectInOrNotIn == null)
            {
                result.SecuritySubjectInORNotIn = InORNotIn.In;
            }
            else
            {
                result.SecuritySubjectInORNotIn = (InORNotIn)item.SecuritySubjectInOrNotIn;
            }
            return(result);
        }
        private List <CodeFunctionColumnDTO> ToCodeFunctionParameterDTO(CodeFunction cItem)
        {
            BizColumn bizColumn = new BizColumn();
            List <CodeFunctionColumnDTO> result = new List <CodeFunctionColumnDTO>();

            foreach (var column in cItem.CodeFunctionParameter)
            {
                result.Add(new CodeFunctionColumnDTO()
                {
                    ID = column.ID, DataType = column.DataType, ParameterName = column.ParamName, DotNetType = Type.GetType(column.DataType)
                });
            }
            return(result);
        }
        //public List<CodeFunction_EntityDTO> GetCodeFunctionEntities(int entityID)
        //{
        //    List<CodeFunction_EntityDTO> result = new List<CodeFunction_EntityDTO>();
        //    using (var projectContext = new DataAccess.MyProjectEntities())
        //    {
        //        //projectContext.Configuration.LazyLoadingEnabled = false;

        //        var listCodeFunction = projectContext.CodeFunction_TableDrivedEntity.Where(x => x.TableDrivedEntityID == entityID);
        //        foreach (var item in listCodeFunction)
        //            result.Add(ToCodeFunction_EntityDTO(item, false));

        //    }
        //    return result;
        //}
        private CodeFunction_EntityDTO ToCodeFunction_EntityDTO(CodeFunction_TableDrivedEntity cItem, bool withColumns)
        {
            BizColumn bizColumn = new BizColumn();
            var       result    = new CodeFunction_EntityDTO();

            result.ID             = cItem.ID;
            result.Title          = cItem.Title;
            result.Name           = cItem.Name;
            result.EntityID       = cItem.TableDrivedEntityID;
            result.CodeFunctionID = cItem.CodeFunctionID;
            result.CodeFunction   = ToCodeFunctionDTO(cItem.CodeFunction, withColumns);
            if (withColumns)
            {
                result.CodeFunctionEntityColumns = ToCodeFunctionEntityColumnsDTO(cItem);
            }

            return(result);
        }
        private void SavePermission(MyProjectEntities context, PermissionDTO permission)
        {
            if (permission.SecurityObjectCategory == DatabaseObjectCategory.Column)
            {
                if (permission.Actions.Any(x => x == SecurityAction.NoAccess))
                {
                    BizColumn bizColumn = new BizColumn();
                    var       column    = bizColumn.GetColumn(permission.SecurityObjectID, true);
                    if (column.PrimaryKey)
                    {
                        throw new Exception("امکان تعیین عدم دسترسی به ستونهای کلید اصلی وجود ندارد");
                    }
                }
            }

            Permission dbItem = null;

            if (permission.ID != 0)
            {
                dbItem = context.Permission.First(x => x.ID == permission.ID);
            }
            else
            {
                dbItem = new Permission();
                context.Permission.Add(dbItem);
            }

            dbItem.SecurityObjectID  = permission.SecurityObjectID;
            dbItem.SecuritySubjectID = permission.SecuritySubjectID;
            //dbItem.SecurityObjectType = (short)permission.SecurityObjectCategory;

            while (dbItem.Permission_Action.Any())
            {
                context.Permission_Action.Remove(dbItem.Permission_Action.First());
            }

            foreach (var item in permission.Actions)
            {
                Permission_Action action = new Permission_Action();
                action.Action = item.ToString();
                dbItem.Permission_Action.Add(action);
            }
        }
        //public int GetCodeFunctionEntityID(int entityID, int CodeFunctionID)
        //{
        //    List<CodeFunction_EntityDTO> result = new List<CodeFunction_EntityDTO>();
        //    using (var projectContext = new DataAccess.MyProjectEntities())
        //    {
        //        //projectContext.Configuration.LazyLoadingEnabled = false;

        //        var item = projectContext.CodeFunction_TableDrivedEntity.FirstOrDefault(x => x.TableDrivedEntityID == entityID && x.CodeFunctionID == CodeFunctionID);
        //        if (item != null)
        //            return item.ID;
        //        else
        //            return 0;

        //    }
        //}
        private List <CodeFunction_Entity_ColumnDTO> ToCodeFunctionEntityColumnsDTO(CodeFunction_TableDrivedEntity cItem)
        {
            BizColumn bizColumn = new BizColumn();
            List <CodeFunction_Entity_ColumnDTO> result = new List <CodeFunction_Entity_ColumnDTO>();

            foreach (var column in cItem.CodeFunction_TableDrivedEntity_Parameters)
            {
                var item = new CodeFunction_Entity_ColumnDTO();
                item.ID = column.ID;
                item.CodeFunctionParameterID = column.CodeFunctionParameterID;
                item.CodeFunction_EntityID   = column.CodeFunction_TableDrivedEntityID;
                item.ColumnID   = column.ColumnID;
                item.ColumnName = column.Column.Name;

                item.FunctionColumnDotNetType = Type.GetType(column.CodeFunctionParameter.DataType);
                item.FunctionColumnParamName  = column.CodeFunctionParameter.ParamName;
                result.Add(item);
            }
            return(result);
        }
        private List <DatabaseFunctionColumnDTO> ToDatabaseFunctionParameterDTO(DatabaseFunction cItem)
        {
            BizColumn bizColumn = new BizColumn();
            List <DatabaseFunctionColumnDTO> result = new List <DatabaseFunctionColumnDTO>();

            foreach (var column in cItem.DatabaseFunctionParameter)
            {
                var item = new DatabaseFunctionColumnDTO()
                {
                    ID            = column.ID,
                    DataType      = column.DataType,
                    Enable        = column.Enable,
                    ParameterName = column.ParamName,
                    DotNetType    = bizColumn.GetColumnDotNetType(column.DataType, false),
                    Order         = column.Order ?? 0,
                    InputOutput   = (Enum_DatabaseFunctionParameterType)column.InputOutput
                };

                result.Add(item);
            }
            return(result);
        }
        public CodeFunctionDTO ToCodeFunctionDTO(CodeFunction item, bool withColumns)
        {
            BizColumn       bizColumn = new BizColumn();
            CodeFunctionDTO result    = new CodeFunctionDTO();

            result.ID        = item.ID;
            result.ClassName = item.ClassName;
            //result.Catalog = item.Catalog;
            //if (item.TableDrivedEntityID != null)
            //    result.EntityID = item.TableDrivedEntityID.Value;
            result.FunctionName     = item.FunctionName;
            result.Name             = item.Name;
            result.ParamType        = (Enum_CodeFunctionParamType)item.Type;
            result.RetrunType       = item.ReturnType;
            result.RetrunDotNetType = Type.GetType(item.ReturnType);
            //if (item.ValueCustomType != null)
            //    result.ValueCustomType = (ValueCustomType)item.ValueCustomType;
            result.Path = item.Path;
            if (withColumns)
            {
                result.Parameters = ToCodeFunctionParameterDTO(item);
            }
            return(result);
        }