55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using HRM_MQ_Consumer_Service.OData;
|
|
using HRM_MQ_Consumer_Service.Structure;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace HRM_MQ_Consumer_Service.Parsers
|
|
{
|
|
internal class CounterpartyJSONParser
|
|
{
|
|
private Logger.Logger _logger;
|
|
private static QDocWrapper _wrapper;
|
|
|
|
public CounterpartyJSONParser()
|
|
{
|
|
_logger = new Logger.Logger("Counterparties_test");
|
|
_wrapper = new QDocWrapper(_logger);
|
|
}
|
|
|
|
public async Task<bool> Parse(string message)
|
|
{
|
|
bool result = false;
|
|
CounterParty company;
|
|
var converted = JsonConvert.DeserializeObject<CounterParty1C>(message);
|
|
var found = await TryFindCompany(converted);
|
|
if (found != null)
|
|
{
|
|
await _wrapper.UpdateCounterparty(found);
|
|
}
|
|
else await _wrapper.CreateCounterparty(converted);
|
|
return result;
|
|
}
|
|
|
|
private async Task<CounterParty> TryFindCompany(CounterParty1C converted)
|
|
{
|
|
CounterParty company;
|
|
|
|
company = await _wrapper.GetCompanyByGuid(converted.Guid);
|
|
|
|
if (company == null)
|
|
{
|
|
company = await _wrapper.GetCompanyByBIN(converted.BIN);
|
|
}
|
|
if (company != null)
|
|
{
|
|
company.UpdCounterparty = new CounterParty { Id = company.Id };
|
|
}
|
|
return company;
|
|
}
|
|
}
|
|
}
|