125 lines
3.7 KiB
C#
125 lines
3.7 KiB
C#
using System;
|
|
using ELT.Client.Models.Common;
|
|
using ELTKasko;
|
|
using ELTOsago;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using AuthInfo = ELTOsago.AuthInfo;
|
|
using EltKaskoSoap = ELTKasko.EltSoap;
|
|
using ELTOsagoSoap = ELTOsago.EltSoap;
|
|
|
|
namespace ELT.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class CommonController : ControllerBase
|
|
{
|
|
private EltKaskoSoap _eltKaskoClient = new ELTKasko.EltSoapClient();
|
|
private ELTOsagoSoap _eltOsagoClient = new ELTOsago.EltSoapClient();
|
|
string _login = Environment.GetEnvironmentVariable("eltLogin");
|
|
string _password = Environment.GetEnvironmentVariable("eltPassword");
|
|
|
|
private GetPreRequestDataOutput GetPreRequestData([FromBody] GetPreRequestDataInput data)
|
|
{
|
|
var mappedCars = _eltKaskoClient.MappedCars(new MappedCarsRequest
|
|
{
|
|
Marka = data.BrandId,
|
|
Model = data.ModelId
|
|
});
|
|
|
|
return new GetPreRequestDataOutput
|
|
{
|
|
Kladr = data.Kladr,
|
|
Brand = mappedCars.Mark,
|
|
Model = mappedCars.Model,
|
|
Modification = mappedCars.Modification?.Name
|
|
};
|
|
}
|
|
|
|
[HttpPost("get-kasko-calculation")]
|
|
public ActionResult<KASKOCalculationResult> GetKaskoCalculation([FromBody] GetKaskoCalculationInput data)
|
|
{
|
|
try
|
|
{
|
|
var preRequestData = this.GetPreRequestData(data.Preparams);
|
|
|
|
var request = data.Params;
|
|
request.UsageCityKLADR = preRequestData.Kladr;
|
|
request.Mark = preRequestData.Brand;
|
|
request.Model = preRequestData.Model;
|
|
|
|
if (request.Modification != null)
|
|
request.Modification.Name = preRequestData.Modification;
|
|
|
|
var specialMachinery = data.Preparams.SpecialMachinery;
|
|
specialMachinery.SpecialMachineryMark = preRequestData.Brand;
|
|
specialMachinery.SpecialMachineryModel = preRequestData.Model;
|
|
request.SpecialMachinery = specialMachinery;
|
|
|
|
var res = _eltKaskoClient.PreliminaryKASKOCalculation(
|
|
new ELTKasko.AuthInfo
|
|
{
|
|
Login = _login,
|
|
Password = _password
|
|
}
|
|
, null
|
|
, data.CompanyId
|
|
, 0
|
|
, 0
|
|
, null
|
|
, null
|
|
, null
|
|
, "13"
|
|
, null
|
|
, false
|
|
, null
|
|
, null
|
|
, request);
|
|
|
|
if (res?.Error is { Length: > 0 })
|
|
{
|
|
return BadRequest(res);
|
|
}
|
|
|
|
return Ok(res);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(500, e.Message);
|
|
}
|
|
}
|
|
|
|
[HttpPost("get-osago-calculation")]
|
|
public ActionResult<OSAGOFullCalculationResponse> GetOsagoCalculation([FromBody] GetOsagoCalculationInput data)
|
|
{
|
|
try
|
|
{
|
|
var prerequestData = this.GetPreRequestData(data.Preparams);
|
|
|
|
var request = data.Params;
|
|
request.UsagePlace = prerequestData.Kladr;
|
|
request.CarInfo.Mark = prerequestData.Brand;
|
|
request.CarInfo.Model = prerequestData.Model;
|
|
|
|
request.AuthInfo = new AuthInfo
|
|
{
|
|
Login = _login,
|
|
Password = _password
|
|
};
|
|
|
|
request.InsuranceCompany ??= data.CompanyId;
|
|
|
|
var res = _eltOsagoClient.OSAGOFullCalculation(data.Params);
|
|
|
|
if (res?.Error is { Length: > 0 })
|
|
{
|
|
return BadRequest(res);
|
|
}
|
|
|
|
return Ok(res);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return StatusCode(500, e.Message);
|
|
}
|
|
}
|
|
} |