Esempio n. 1
0
        public ActionResult Index()
        {
            var vm = InitializeViewModel();

            int entityId;

            if (int.TryParse(Request.QueryString["entityId"], out entityId))
            {
                vm.MapToEntity = entityId;
                vm             = GetEntityFields(vm);
            }

            int mapId;

            if (int.TryParse(Request.QueryString["mapId"], out mapId))
            {
                var dataMap = dataFlowDbContext.DataMaps.FirstOrDefault(x => x.Id == mapId);

                if (dataMap != null)
                {
                    vm.DataMapId   = dataMap.Id;
                    vm.MapName     = dataMap.Name;
                    vm.MapToEntity = dataMap.EntityId;
                    vm.Manual      = dataMap.Manual;

                    dataMap.Map = dataMap.Map.Replace("lookup_table", "lookup-table");

                    if (dataMap.Manual)
                    {
                        vm.JsonMap = dataMap.Map;
                    }
                    else
                    {
                        vm = GetEntityFields(vm);
                        var dataMappers = JsonConvert.DeserializeObject <List <DataMapper> >(dataMap.Map, DataMapper.JsonSerializerSettings);
                        vm.JsonMap = JsonConvert.SerializeObject(dataMappers, DataMapper.JsonSerializerSettings);
                        vm.Fields  = DataMapperBuilder.BuildPropertyUniqueKey(dataMappers);
                    }
                }
            }

            if (TempData["CsvColumnHeaders"] is string)
            {
                vm.CsvColumnHeaders = ((string)TempData["CsvColumnHeaders"]).Split(',').ToList();
            }

            if (TempData["CsvDataPreview"] is DataTable)
            {
                vm.CsvPreviewDataTable = (DataTable)TempData["CsvDataPreview"];
            }

            if (TempData["IsSuccess"] is bool)
            {
                vm.IsSuccess = (bool)TempData["IsSuccess"];
            }

            if (TempData["ShowInfoMessage"] is bool)
            {
                vm.ShowInfoMessage = (bool)TempData["ShowInfoMessage"];
            }

            if (TempData["InfoMessage"] is string)
            {
                vm.InfoMessage = (string)TempData["InfoMessage"];
            }

            return(View(vm));
        }
Esempio n. 2
0
        private DataMapperViewModel GetEntityFields(DataMapperViewModel vm)
        {
            var entitySelected = dataFlowDbContext.Entities.FirstOrDefault(x => x.Id == vm.MapToEntity);

            if (!string.IsNullOrWhiteSpace(entitySelected?.Url))
            {
                string apiUrl = base.ConfigurationService.GetConfigurationByKey(Constants.API_SERVER_URL).Value;
                apiUrl = DataFlow.Common.Helpers.UrlUtility.GetUntilOrEmpty(apiUrl.Trim(), "/api/"); //get just the base URL

                var entityJson = edFiMetadataProcessor.GetJsonFromUrl(apiUrl, entitySelected.Url);
                var apiFields  = edFiMetadataProcessor.GetFieldListFromJson(entityJson, entitySelected.Name)
                                 .Where(x => x.Required || GetAdditionalFields(entitySelected.Name).Contains(x.Name))
                                 .ToList();

                apiFields.ForEach(x =>
                {
                    if (x.Name == "id")
                    {
                        return;
                    }

                    var dataMapperField = new DataMapper(
                        name: x.Name,
                        dataMapperProperty: new DataMapperProperty(
                            dataType: x.Type,
                            childType: !string.IsNullOrWhiteSpace(x.SubType) ? x.Name : string.Empty
                            ));
                    if (!string.IsNullOrWhiteSpace(x.SubType) && x.SubFields.Any())
                    {
                        x.SubFields.ForEach(subField =>
                        {
                            if (subField.Name == "id")
                            {
                                return;
                            }
                            ;
                            var subDataMapper = new DataMapper();

                            if (subField.Required || GetAdditionalFields(x.Name).Contains(subField.Name))
                            {
                                subDataMapper = new DataMapper(
                                    name: subField.Name,
                                    dataMapperProperty: new DataMapperProperty(
                                        dataType: subField.Type,
                                        childType: !string.IsNullOrWhiteSpace(subField.SubType) ? subField.Name : string.Empty
                                        ));
                                dataMapperField.SubDataMappers.Add(subDataMapper);
                            }

                            if (!string.IsNullOrWhiteSpace(subField.SubType) && subField.SubFields.Any())
                            {
                                subField.SubFields.ForEach(triField =>
                                {
                                    if (triField.Name == "id")
                                    {
                                        return;
                                    }

                                    if (triField.Required)
                                    {
                                        var triDataMapper = new DataMapper(
                                            name: triField.Name,
                                            dataMapperProperty: new DataMapperProperty(
                                                dataType: triField.Type,
                                                childType: !string.IsNullOrWhiteSpace(triField.SubType) ? triField.Name : string.Empty
                                                ));

                                        subDataMapper.SubDataMappers.Add(triDataMapper);
                                    }
                                });
                            }
                        });
                    }

                    var dataMappers = new List <DataMapper> {
                        dataMapperField
                    };
                    var builder = DataMapperBuilder.BuildPropertyUniqueKey(dataMappers);

                    vm.Fields.AddRange(builder);
                });
            }
            return(vm);
        }