bgmulinari / B1SLayer

A lightweight SAP Business One Service Layer client for .NET
MIT License
136 stars 47 forks source link

string-mode for batch-method #13

Closed sofdwere closed 1 year ago

sofdwere commented 2 years ago

I have used your method PatchStringAsync, which takes the JSON data as direct string. But there seems to be no method like PostBatchStringAsync. Can you add somethink like that?

Just for testing I used this variant:

slBatchRequests.Add(new SLBatchRequest(new System.Net.Http.HttpMethod("PATCH"), "Items('01003')", "{\"ItemPrices\": [{ \"PriceList\": 111,\"Price\": 97.9}]}"));
slBatchRequests.Add(new SLBatchRequest(new System.Net.Http.HttpMethod("PATCH"), "Items('01003')", "{\"ItemxPrices\": [{ \"PriceList\": 111,\"Price\": 98.9}]}"));
slBatchRequests.Add(new SLBatchRequest(new System.Net.Http.HttpMethod("PATCH"), "Items('01003')", "{\"ItemPrices\": [{ \"PriceList\": 111,\"Price\": 98.9}]}"));
System.Net.Http.HttpResponseMessage[] batchResult = await serviceLayer.PostBatchAsync(slBatchRequests, false, true);
public async Task<HttpResponseMessage[]> PostBatchAsync(IEnumerable<SLBatchRequest> requests, bool singleChangeSet = true, bool contentAsString = false)
{
if (contentAsString)
{
    request.Content = new Flurl.Http.Content.CapturedStringContent((string)batchRequest.Data);
}
else
{
    request.Content = new StringContent(JsonConvert.SerializeObject(batchRequest.Data, batchRequest.JsonSerializerSettings), batchRequest.Encoding, "application/json");
}
bgmulinari commented 2 years ago

Hi, @sofdwere. I think it's a good addition to the library and I'll look into adding it for the next release. Thanks for your suggestion!

bgmulinari commented 1 year ago

Hi, @sofdwere. This is now possible in version 1.3.0, however, there's no need to specify that you are sending a JSON string.