Controllers: add try/catch to CommonController.cs

This commit is contained in:
vchikalkin 2023-10-06 12:40:35 +03:00
parent b42a9bb284
commit 564ea80ef7

View File

@ -3,6 +3,7 @@ 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;
@ -37,74 +38,88 @@ public class CommonController : ControllerBase
[HttpPost("get-kasko-calculation")]
public ActionResult<KASKOCalculationResult> GetKaskoCalculation([FromBody] GetKaskoCalculationInput data)
{
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 })
try
{
return BadRequest(res);
}
var preRequestData = this.GetPreRequestData(data.Preparams);
return Ok(res);
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)
{
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 ELTOsago.AuthInfo
try
{
Login = _login,
Password = _password
};
var prerequestData = this.GetPreRequestData(data.Preparams);
request.InsuranceCompany ??= data.CompanyId;
var request = data.Params;
request.UsagePlace = prerequestData.Kladr;
request.CarInfo.Mark = prerequestData.Brand;
request.CarInfo.Model = prerequestData.Model;
var res = _eltOsagoClient.OSAGOFullCalculation(data.Params);
request.AuthInfo = new AuthInfo
{
Login = _login,
Password = _password
};
if (res?.Error is { Length: > 0 })
{
return BadRequest(res);
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);
}
return Ok(res);
}
}