0

I have huge problems with building an JSON-payload. Hopefully, someone can give me a push in the right direction. With PostMan it's easy to CRUD-Articles, with C# i'm struggling here.

The UomUnitPrices makes me headache.

First of all, i need to do it in

  • .Net35
  • RestSharp 105.2.3.0
  • Newtonsoft.Json 13.0.0.0

I'm struggeling with List in List's

{
    "Id": "10006",
    "Barcodes": [
        {
            "Barcode": "1010006"
        }
    ],
    "UomUnitPrices": [
        {
            "Prices": [
                {
                    "PriceLevelId": "1",
                    "PriceValue": 5.000
                }
            ]
        }
    ]
}

The payload i should create, looks like this:

{
    "Id": "10006",
    "Barcodes": [
        {
            "Barcode": "1010006"
        }
    ],
    "UomUnitPrices": [
        {
            "Prices": [
                {
                    "PriceLevelId": "1",
                    "PriceValue": 5.000
                },
                {
                    "PriceLevelId": "100",
                    "PriceValue": 20.000
                },
                {
                    "PriceLevelId": "200",
                    "PriceValue": 10.000
                },
                {
                    "PriceLevelId": "300",
                    "PriceValue": 15.000
                },
                {
                    "PriceLevelId": "400",
                    "PriceValue": 17.500
                }
            ]
        }
    ],
    "Description": "Article Description",
    "GroupAId": "50",
    "VisibilityCriteriaId": "1",
    "IsValid": true,
    "MeasureUnitId": "pcs",
    "Vat1Id": "1",
    "Vat2Id": "2"
}

All works, except the "UomUnitPrices"-List with the "Prices"-List in it.

public partial class ArticlesDTO
{
    ...
    [JsonProperty("UomUnitPrices")]
    public List<UomUnitPrice> UomUnitPrices { get; set; }
    ...
}

public partial class UomUnitPrice
{
    [JsonProperty("Prices")]
    public IList<Price> Prices { get; set; }
}

public partial class Price
{
    [JsonProperty("PriceLevelId")]
    public string PriceLevelId { get; set; }

    [JsonProperty("PriceValue")]
    public double PriceValue { get; set; }
}

public partial class ArticlesDTO
{
     public ArticlesDTO CreateArticle(string id, string description, string groupAid, bool isValid, string measureUnitId, string vat1Id, string vat2Id)
    {
        Barcode barcode = new Barcode().CreateBarcode("String Barcode");
        UomUnitPrice uomUnitPrice = new UomUnitPrice().UomUnitPriceList(); //Here i need a solution

        ArticlesDTO article = new ArticlesDTO()
        {
            Id = id,
            Description = description,
            GroupAId = groupAid,
            VisibilityCriteriaId = 1,
            IsValid = true,
            MeasureUnitId = measureUnitId,
            Vat1Id = vat1Id,
            Vat2Id = vat2Id,
            Barcodes = new List<Barcode>() { barcode },
            UomUnitPrices = new List<UomUnitPrice>() { uomUnitPrice } // That can't be that hard...
        };
        return article;
    }
    public ArticlesDTO CreateArticle(DataRow dataRow)...
}

Can somebody give me an advice how to solve that problem.

It's so humbling that I can't solve the problem myself. I watched several youtube/udemy -videos, read a lot on stackoverflow (especially this topic), but it wouldn't solve my problem.

Finally i would create the "Articles"-JSON-payload with a System.Data.DataRow. But as long as I can't even create that payload, it's going to be a long road to get there.

Any help/advice is appreciated.

1

1 Answer 1

-1

Try to switch your Prices type to only List instead of IList

Sign up to request clarification or add additional context in comments.

2 Comments

this could go in a comment instead.
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.