public HttpResponseMessage GetMetaModuleInstanceData(bool isConfigView, string metaInstanceId = null)
        {
            ModuleDefinition module = null;
            Guid id = new Guid();
            string data = string.Empty;

            using (new IhMonitoredScope("ModuleInstanceApiV1Controller - GetMetaModuleInstanceData"))
            {
                if (!string.IsNullOrEmpty(metaInstanceId))
                {
                    id = new Guid(metaInstanceId);
                    module = ServiceContext.ModuleRegistry.GetModule(id);
                }

                ModuleInstanceModel model = new ModuleInstanceModel(id);

                if (module == null)
                {
                    model.IsNewRecord = true;
                    data = JsonConvert.SerializeObject(model);
                    return CreateResponse(data, HttpStatusCode.OK);
                }
                else
                {
                    var moduleInstance = module.Instances.Single(i => i.Id == id);
                    var parameters = CreateCommonParameters("ModuleInstanceView", moduleInstance.ModuleName, moduleInstance.ModuleViewName, isConfigView);
                    var dataProvider = ServiceContext.DataProviderFactory.CreateDataProvider(module.CmsType);
                    var dataProviderResponse = dataProvider.PostModuleData(module, parameters, moduleInstance.SettingsData);
                    data = dataProviderResponse.Data;
                    if (isConfigView)
                    {
                        model.SettingsData = data;
                        var jsonModelData = JsonConvert.SerializeObject(model);
                        return CreateResponse(jsonModelData, HttpStatusCode.OK);
                    }
                    else
                    {
                        return CreateResponse(data, HttpStatusCode.OK);
                    }
                }
            }
        }
        public HttpResponseMessage GetModuleInstanceData(bool isConfigView, string moduleInstanceId = null)
        {
            ModuleInstanceModel model;
            var data = string.Empty;
            var responseParameters = new Dictionary<string, string>();

            using (new IhMonitoredScope("ModuleInstanceApiV1Controller - GetModuleInstanceData"))
            {
                if (string.IsNullOrEmpty(moduleInstanceId) || ServiceContext.ModuleRegistry.GetModule(new Guid(moduleInstanceId)) == null)
                {
                    //New Module Instance
                    var id = string.IsNullOrEmpty(moduleInstanceId) ? Guid.NewGuid() : new Guid(moduleInstanceId);

                    model = new ModuleInstanceModel(id);
                    model.ModuleDefinitions = ServiceContext.ModuleRegistry
                        .GetModules(true)
                        .Select(m => new ModuleDefinitionModel(m))
                        .Where(m => m.Name != "meta")
                        .OrderBy(m => m.DisplayName).ToList();
                    model.IsNewRecord = true;
                }
                else
                {
                    //Build Module Instance Model
                    var id = new Guid(moduleInstanceId);
                    var module = ServiceContext.ModuleRegistry.GetModule(id);
                    var moduleInstance = module.Instances.Single(i => i.Id == id);
                    model = new ModuleInstanceModel(id);

                    model.ModuleName = module.Name;
                    model.ModuleViewName = module.Views.First(v => v.Name == moduleInstance.ModuleViewName).Name;
                    model.ModuleDisplayName = module.DisplayName;
                    model.ModuleViewDisplayName = module.Views.First(v => v.Name == moduleInstance.ModuleViewName).DisplayName;
                    model.TemplateName = moduleInstance.TemplateName;
                    model.DisplayName = moduleInstance.DisplayName;
                    model.IsReusable = moduleInstance.IsReusable;

                    // Gather request parameters
                    var parameters = CreateCommonParameters("ModuleInstanceView", moduleInstance.ModuleName, moduleInstance.ModuleViewName, isConfigView);

                    // Send data to data provider to get Settings Data
                    var dataProvider = ServiceContext.DataProviderFactory.CreateDataProvider(module.CmsType);
                    var dataProviderResponse = dataProvider.PostModuleData(module, parameters, moduleInstance.SettingsData);

                    model.SettingsData = dataProviderResponse.Data;
                    responseParameters = dataProviderResponse.Parameters;
                }

                model.IsEditMode = isConfigView;
            }

            model.DiagnosticOutput = ServiceContext.DiagnosticManager.GetDiagnosticOutput();

            data = JsonConvert.SerializeObject(model);

            // Create and return response
            return CreateResponse(data, responseParameters, HttpStatusCode.OK);
        }