예제 #1
0
        public async Task <IActionResult> AddModel([FromBody] KeyValuePairViewModel vm)
        {
            //the vm.id here is the make id.
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            context.Models.Add(new Model {
                MakeId = vm.Id, Name = vm.Name
            });
            await context.SaveChangesAsync();

            return(Ok());
        }
예제 #2
0
        public async Task <IActionResult> AddMake([FromBody] KeyValuePairViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //var vehicle = mapper.Map<SaveVehicleViewModel, Vehicle>(vm);
            context.Makes.Add(new Make {
                Name = vm.Name
            });
            await context.SaveChangesAsync();

            return(Ok());
        }
        public static SwagData FromFile(String file, IEnumerable <KeyValuePairViewModel <String, ParseViewModel> > parseMappers)
        {
            String filename = Path.GetFileName(file);
            String ext      = Path.GetExtension(file).TrimStart('.');

            KeyValuePairViewModel <String, ParseViewModel> parseMapper = parseMappers.FirstOrDefault(pm => pm.Key != null && pm.Key.ToLower() == ext.ToLower());

            if (parseMapper != null)
            {
                switch (parseMapper.Value.ParseStrategy)
                {
                case ParseStrategy.Csv:
                case ParseStrategy.Dbf:
                    DataTableConvertContext dataTableConvertContext = new DataTableConvertContext();
                    switch (parseMapper.Value.ParseStrategy)
                    {
                    case ParseStrategy.Csv:
                        dataTableConvertContext.Converter = new DataTableCsvFileConverter();
                        break;

                    case ParseStrategy.Dbf:
                        dataTableConvertContext.Converter = new DataTableDbfFileConverter();
                        break;
                    }
                    dataTableConvertContext.Params = new DataTableConvertParams();
                    PropertyCopy.Copy(parseMapper.Value, dataTableConvertContext.Params);
                    DataTableConverterHelper.ConverterFileContexts[ext] = dataTableConvertContext;
                    break;

                case ParseStrategy.Xml:
                case ParseStrategy.Json:
                    DataSetConvertContext dataSetConvertContext = new DataSetConvertContext();
                    switch (parseMapper.Value.ParseStrategy)
                    {
                    case ParseStrategy.Xml:
                        dataSetConvertContext.Converter = new DataSetXmlFileConverter();
                        break;

                    case ParseStrategy.Json:
                        dataSetConvertContext.Converter = new DataSetJsonFileConverter();
                        break;
                    }
                    dataSetConvertContext.Params = new DataSetConvertParams();
                    PropertyCopy.Copy(parseMapper.Value, dataSetConvertContext.Params);
                    DataSetConverterHelper.ConverterFileContexts[ext] = dataSetConvertContext;
                    break;
                }
            }

            DataSetConvertContext dataSetContext = DataSetConverterHelper.ConverterFileContexts[ext];

            if (dataSetContext != null)
            {
                return(new SwagDataSet(dataSetContext.ToDataSet(file))
                {
                    Display = filename
                });
            }

            DataTableConvertContext dataTableContext = DataTableConverterHelper.ConverterFileContexts[ext];

            if (dataTableContext != null)
            {
                return(new SwagDataTable(dataTableContext.ToDataTable(file))
                {
                    Display = filename
                });
            }

            return(null);
        }