-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTestService.cs
65 lines (56 loc) · 2.84 KB
/
TestService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using DataOperations;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace GWSAMPLE_BASIC
{
public class TestService : BackgroundService, IHostedService
{
private readonly ILogger _logger;
private readonly IOperationsDispatcher _dispatcher;
public BusinessPartnerSet bps;
public ProductSet ps;
public SalesOrderSet sos;
public SalesOrderLineItemSet sols;
public TestService(ILogger<TestService> logger, IOperationsDispatcher dispatcher, SalesOrderSet _sos, SalesOrderLineItemSet _sols, ProductSet _ps, BusinessPartnerSet _bps)
{
_logger = logger;
_dispatcher = dispatcher;
this.sos = _sos;
this.sols = _sols;
this.ps = _ps;
this.bps = _bps;
}
protected async override Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Test is starting...");
// get me a sales order line item with id 0500000000 and pull the city asynchronously from the business partner
var salesOrderInput = await sos.GetAsync("0500000000");
_logger.LogInformation((await salesOrderInput.ToBusinessPartner.GetAsync()).Address.City);
// get product 'ht-1023'
var product = await ps.GetAsync("HT-1023");
// get business partner '0100000001', update the address building to "16 Brook Meadow"
var businessPartner = await bps.GetAsync("0100000001");
businessPartner.Address.Building = "16 Brook";
await bps.UpdateAsync(businessPartner);
// Dump all salesOrderLineItem numbers to the console one by one (!)
(await sos.GetListAsync()).ToList().ForEach(salesOrderLineItem => {
Console.WriteLine($"Sales Order: {salesOrderLineItem.SalesOrderID}");
});
// get me a sales order line item with id 0500000000 at position 10 and update the note to "Test Note"
// be aware of required states of the sales orders in SAP for this service: https://blogs.sap.com/2019/06/06/es5-error-message-create-is-not-allowed-because-of-property-value/
var selectors = new Dictionary<string, object>();
selectors.Add("SalesOrderID", "0500000000");
selectors.Add("ItemPosition", "0000000010");
var salesOrderLineItem = await sols.GetAsync(selectors);
salesOrderLineItem.Note = "Test Note";
await sols.UpdateAsync(salesOrderLineItem);
Product pro = await ps.GetAsync("HT-1023");
if(pro.ProductID != "HT-1023") throw new Exception("Failed GET");
_logger.LogInformation(pro.Description);
_logger.LogInformation("Test is complete.");
}
}
}