BExISMigration.DataStructureCreator.existingDataStructures C# (CSharp) Метод

existingDataStructures() приватный Метод

private existingDataStructures ( DataTable mapVariables, string dataSetID ) : StructuredDataStructure
mapVariables System.Data.DataTable
dataSetID string
Результат BExIS.Dlm.Entities.DataStructure.StructuredDataStructure
        private StructuredDataStructure existingDataStructures(DataTable mapVariables, string dataSetID)
        {
            DataStructureManager dataStructureManager = new DataStructureManager();
            StructuredDataStructure dataStructure = new StructuredDataStructure();

            // get alldatasetId respective variables-rows from mapped-variables-table
            DataRow[] mappedRows = mapVariables.Select("DatasetId = '" + dataSetID + "' AND Block = 0");

            // get all datastrcutures from repo which has the same number of variables
            List<StructuredDataStructure> existDatastructures = dataStructureManager.StructuredDataStructureRepo.Get(s =>
                mappedRows.Count().Equals(s.Variables.Count)).ToList();

            foreach (StructuredDataStructure existDs in existDatastructures)
            {
                bool isEqualStructure = true;
                //foreach (DataRow mapRow in mapVariables.Rows)
                foreach (DataRow mapRow in mappedRows)
                {
                    int exvarno = existDs.Variables.Where(v =>
                        Convert.ToInt64(mapRow["UnitId"]).Equals(v.Unit.Id) &&
                        mapRow["Name"].ToString().Equals(v.Label) &&
                        Convert.ToInt64(mapRow["AttributeId"]).Equals(v.DataAttribute.Id)
                        ).Count();
                    if (exvarno == 0)
                    {
                        isEqualStructure &= false;
                        break;
                    }
                }
                if (isEqualStructure)
                {
                    dataStructure = existDs;
                    break;
                }
            }

            return dataStructure;
        }