public string bindModelwithFields(HealthModel _model, HealthVaultFields _nonPremitiveField, string mTypeModelObject, string mcurrentModelType) { StringBuilder _strModuleScript = new StringBuilder(); _nonPremitiveField.healthVaultFields.ForEach(_field => { if (_field.isPremitive == false) { if (_field.CollectionObject) { _strModuleScript.AppendFormat("List<{0}Model> _{0} = new List<{0}Model>();", _field.FieldName); _strModuleScript.AppendFormat("foreach (var __{0} in {1}.{2}.{0})", _field.FieldName, mcurrentModelType, _nonPremitiveField.FieldName); _strModuleScript.Append("{"); _strModuleScript.AppendFormat("{0}Model obj{0} = new {0}Model();", _field.FieldName); _strModuleScript.Append(bindModelwithFields(_model, _field, "obj" + _field.FieldName, mcurrentModelType + "." + _field.FieldName)); _strModuleScript.AppendFormat("_{0}.Add(obj{0});", _field.FieldName); _strModuleScript.Append("}"); //_strModuleScript.AppendFormat("{0}Model.{1}=_{1};", _nonPremitiveField.FieldName, _field.FieldName); _strModuleScript.AppendFormat("obj{0}.{1}=_{1};", _nonPremitiveField.FieldName, _field.FieldName); } else { _strModuleScript.Append(bindModelwithFields(_model, _field, "__" + _field.FieldName, mcurrentModelType + "." + _field.FieldName)); } } else { if (_field.CollectionObject) { _strModuleScript.AppendFormat("{0}.{1}=\"\";", mTypeModelObject, _field.FieldName); _strModuleScript.AppendFormat("foreach (var _{0} in {1}.{0})", _field.FieldName, "__" + _nonPremitiveField.FieldName); _strModuleScript.Append("{"); _strModuleScript.AppendFormat("{0}.{1}={0}.{1} +{2}", mTypeModelObject, _field.FieldName, createFieldAssignment(_field.FieldType, "__" + _nonPremitiveField.FieldName + "." + _field.FieldName)); _strModuleScript.Append("}"); } else { _strModuleScript.AppendFormat("{0}.{1}={2}", mTypeModelObject, _field.FieldName, createFieldAssignment(_field.FieldType, "__" + _nonPremitiveField.FieldName + "." + _field.FieldName)); } } }); return _strModuleScript.ToString(); }
internal static List<HealthModel> gethealthVaultModelStructure() { List<HealthModel> healthVaultModules = new List<HealthModel>(); #region This Will loop through All Healthvault Modules fetched from Database foreach (var _healthvaultModule in _healthvaultTypes) { //Create a new HealthModel Once We fetch It Will will add it into List<HealthModel> //Instantiate new Health model var healthVaultModule = new HealthModel(); //Instantiate new Healthvault Module Type so that to add it into HealthModel #region Fetch Healthvault Module Type var __healthVaultModule = new HealthVaultType(); var __healthVaultModuleFields = new List<HealthVaultFields>(); #region Fetch Basic Healthvault Type Fields __healthVaultModule.ID = _healthvaultModule.ID; __healthVaultModule.TypeName = _healthvaultModule.TypeName; __healthVaultModule.ModuleID = new Guid(Convert.ToString(_healthvaultModule.ModuleID)); __healthVaultModule.TypeIDs = _healthvaultModule.TypeIDs; __healthVaultModule.ClassName = _healthvaultModule.ClassName; __healthVaultModule.keyColumn = _healthvaultModule.keyColumn; __healthVaultModule.keyColumnValue = _healthvaultModule.keyColumnValue; healthVaultModule.healthVaultModule = __healthVaultModule; #endregion //Fetch All Module to Type mappings in P for the present Module var p = from mapping in _typemappings where mapping.ModuleID == healthVaultModule.healthVaultModule.ID select mapping; #region Go through Each Field Fetched from Datbases and Compare it against the Fields for this module _fields.ForEach( #region _field contains the present value from _fields in Enemurator ( ie health valut data types) _field => p.ToList<HealthVaultTypeFieldMapping>().ForEach( #region _p contains the present value from Module Field Mapping so as to compare with all fields for present Module _p => { // Compare with Typemapping table MastertypeId with HelthVault table FiledId for Module to Field Mapping if (_p.MasterTypeID == _field.FieldID) { #region If the current field in Feild collection is found in Type Mapping Collection var _fieldModel = new HealthVaultFields(); // Fetching All the Field - Field Mapping for Current Field _fieldModel.FieldID = _field.FieldID; _fieldModel.FieldName = _field.FieldName; _fieldModel.FieldType = _field.FieldType; _fieldModel.isPremitive = _field.isPremitive; _fieldModel.PremitiveType = _field.PremitiveType; if (_p.isCollection) { _fieldModel.CollectionObject = true; } //If the Field Does Have any more fields inside if (_field.isPremitive == false) { _fieldModel.healthVaultFields = getChildFields(_field); } __healthVaultModuleFields.Add(_fieldModel); #endregion } healthVaultModule.healtVaultModuleields = __healthVaultModuleFields; } #endregion ) #endregion ); #endregion #endregion healthVaultModules.Add(healthVaultModule); } #endregion return healthVaultModules; }