Hi,
I have a json like this. My goal is to pull data from the database with dapper and fill the model, and then I will post it to the API with json. Would you help me with this topic?
Json
{
"fldWarehouseCompanyId": 9, //LTB Code
"fldSkuCode": "010095145414911200", //Sku
"fldSkuName": "SMARTY Y", //Model Article Name
"fldVolume": 0,
"fldWeight": 0,
"fldDeci": 0,
"fldBrand": "LITTLE BIG", //Brand
"fldGroupCode1": "ERKEK", //Gender
"fldGroupCode2": "PANTOLON", //Product Sub Group
"fldGroupCode3": "SEZONSUZ", //Season
"fldGroupCode4": "GRUP KODU 4", //Boş
"fldGroupCode5": "GRUP KODU 5", //Boş
"fldDefaultUnitId": 52, //Unit
"fldMaxStockLevel": 0,
"fldMinStockLevel": 0,
"fldOrderStockLevel": 0,
"fldPrice": 12345.123, //Price
"fldExtraField1": "BLACK WASH", //Washing
"fldExtraField2": "Denim", //Material
"fldExtraField3": "TR", //Origin
"fldExtraField4": "EKSTRA ALAN 4", //Boş
"fldExtraField5": "EKSTRA ALAN 5", //Boş
"fldExtraField6": "EKSTRA ALAN 6", //Boş
"fldExtraField7": "EKSTRA ALAN 7", //Boş
"fldExtraField8": "EKSTRA ALAN 8", //Boş
"fldExtraField9": "EKSTRA ALAN 9", //Boş
"fldExtraField10": "EKSTRA ALAN 10", //Boş
"skuVariants": [
{
"fldVariant1TypeId": 168,
"fldVariant1TypeName": "MAVİ", //MainColor
"fldVariant2TypeId": 169,
"fldVariant2TypeName": "32", //Size
"fldVariant3TypeId": 169,
"fldVariant3TypeName": "29", //Boy
"skuVariantBarcodes": [
{
"fldBarcode": "8682343691668", //Barcode
"fldIsDefault": true
}
]
},
{
"fldVariant1TypeId": 168,
"fldVariant1TypeName": "MAVİ", //MainColor
"fldVariant2TypeId": 169,
"fldVariant2TypeName": "32", //Size
"fldVariant3TypeId": 169,
"fldVariant3TypeName": "29", //Boy
"skuVariantBarcodes": [
{
"fldBarcode": "8682343691774",
"fldIsDefault": true
}
]
}
]
}
Class
public class Model
{
public int fldWarehouseCompanyId { get; set; } = 9;
public string fldSkuCode { get; set; }
public string fldSkuName { get; set; }
public int fldVolume { get; set; } = 0;
public int fldWeight { get; set; } = 0;
public int fldDeci { get; set; } = 0;
public string fldBrand { get; set; }
public string fldGroupCode1 { get; set; }
public string fldGroupCode2 { get; set; }
public string fldGroupCode3 { get; set; }
public string fldGroupCode4 { get; set; }
public string fldGroupCode5 { get; set; }
public int fldDefaultUnitId { get; set; } = 52;
public int fldMaxStockLevel { get; set; } = 0;
public int fldMinStockLevel { get; set; } = 0;
public int fldOrderStockLevel { get; set; } = 0;
public decimal fldPrice { get; set; }
public List<SkuVariant> skuVariants { get; set; }
}
public class SkuVariant
{
public string Key { get; set; }
public string Value { get; set; }
public List<SkuVariantBarcode> skuVariantBarcodes { get; set; }
}
public class SkuVariantBarcode
{
public string Key { get; set; }
public bool Value { get; set; } = true;
}
Query
var query = "Select \r\nAL.[Articel.Code] AS fldSkuCode, \r\nAL.[Model.ArticelName] AS fldSkuName, \r\nAL.[BrandDefinition.Title] AS fldBrand, \r\nAL.[GenderDefinition.Turkish] AS fldGroupCode1, \r\nAL.[ProductSubGroupDefinition.Turkish] AS fldGroupCode2, \r\nAL.[SeasonDefinition.Title] AS fldGroupCode3, \r\n(Select RRPPrice from ProductPrice where OwnerList='D686551F-73B5-4FE9-99C3-50D3F862F674' and AL.[Articel.Oid] = Product) AS fldPrice,\r\nAL.[WashingDefinition.Title] AS fldExtraField1,\r\nAL.[MaterialDefinition.Turkish] AS fldExtraField2, \r\nBD.Origin_Turkish AS fldExtraField3, \r\n\r\nBS.Value AS skuVariants ,\r\nBSC.Value AS skuVariants,\r\nAL.[BarcodeDefinition.Value] AS fldBarcode\r\nfrom vw_ArticelHorVerValueInfo AL\r\nleft join BarcodeDetailInfo BD ON BD.[BarcodeDefinition.Oid] = AL.[BarcodeDefinition.Oid]\r\nleft join BaseColorSizeDimensionValue BS ON BS.Oid = AL.[CSDV_H.Oid]\r\nleft join BaseColorSizeDimensionValue BSC ON BSC.Oid = AL.[CSDV_V.Oid]\r\n\r\nWhere AL.[Articel.Oid]='a6f661d7-77eb-4e89-901c-ab69f22b65b1'";
Controller
using (var connection = _context.CreateConnection())
{
connection.Open();
var models = connection.Query<Model>(query);
foreach (var item in models)
{
serTransModel = new SerTransModel
{
fldSkuCode = item.fldSkuCode,
fldSkuName = item.fldSkuName,
fldBrand = item.fldBrand,
fldGroupCode1 = item.fldGroupCode1,
fldGroupCode2 = item.fldGroupCode2,
fldGroupCode3 = item.fldGroupCode3,
fldGroupCode4 = item.fldGroupCode4,
fldGroupCode5 = item.fldGroupCode5,
fldPrice = item.fldPrice,
fldExtraField1 = item.fldExtraField1,
fldExtraField2 = item.fldExtraField2,
fldExtraField3 = item.fldExtraField3,
skuVariants = item.skuVariants,
};
}