From 564ea80ef78f1059e7115bd1efc7b5f616f3ba80 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 6 Oct 2023 12:40:35 +0300 Subject: [PATCH] Controllers: add try/catch to CommonController.cs --- ELT/Controllers/CommonController.cs | 129 ++++++++++++++++------------ 1 file changed, 72 insertions(+), 57 deletions(-) diff --git a/ELT/Controllers/CommonController.cs b/ELT/Controllers/CommonController.cs index b3ee465..901b280 100644 --- a/ELT/Controllers/CommonController.cs +++ b/ELT/Controllers/CommonController.cs @@ -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 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 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); } } \ No newline at end of file