public async Task <ActionResult> CalcularPremioSeguro([FromBody] SeguradoSearchDto segurado) { List <IFilter> filters = null; CalculoSeguroDto calculoSeguroDto = null; try { calculoSeguroDto = new CalculoSeguroDto(); //Selecionar veículos segurado filters = new List <IFilter>(); filters.Add(new FilterObj { FilterName = "numerocpf", FilterValue = segurado.NumeroCPF }); calculoSeguroDto.ListVeiculo = await _veiculoService.GetByFilter(filters);; //Selecionar segurado filters = new List <IFilter>(); filters.Add(new FilterObj { FilterName = "numerocpf", FilterValue = segurado.NumeroCPF }); calculoSeguroDto.Segurado = await _seguradoService.GetSingle(filters); var result = await _seguroVeiculoService.CalcularSeguro(calculoSeguroDto); string urlGetCalculos = "/CalculoSeguroList"; var resultAction = new ResultAction("Calculo incluído com sucesso", true, urlGetCalculos); return(Created(new Uri(urlGetCalculos), resultAction)); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public async void UnitTestCalculoPremio() { List <IFilter> filters = null; CalculoSeguroDto calculoSeguroDto = null; var result = default(object); SeguradoSearchDto segurado = null; try { using (var service = _services.BuildServiceProvider()) { calculoSeguroDto = new CalculoSeguroDto(); segurado = new SeguradoSearchDto { NumeroCPF = "70769777619" }; veiculoService = service.GetService <IVeiculoService>(); seguradoService = service.GetService <ISeguradoService>(); seguroVeiculoService = service.GetService <ISeguroVeiculoService>(); //Selecionar veículos segurado filters = new List <IFilter>(); filters.Add(new FilterObj { FilterName = "numerocpf", FilterValue = segurado.NumeroCPF }); calculoSeguroDto.ListVeiculo = await veiculoService.GetByFilter(filters);; //Selecionar segurado filters = new List <IFilter>(); filters.Add(new FilterObj { FilterName = "numerocpf", FilterValue = segurado.NumeroCPF }); calculoSeguroDto.Segurado = await seguradoService.GetSingle(filters); result = await seguroVeiculoService.CalcularSeguro(calculoSeguroDto); } Assert.AreEqual(true, result != null); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public async Task <object> CalcularSeguro(CalculoSeguroDto calculoSeguroDto) { decimal taxaRisco = 0; decimal premioRisco = 0; decimal premioPuro = 0; List <SeguroVeiculo> segurosResult = null; List <IFilter> filters = null; try { segurosResult = new List <SeguroVeiculo>(); foreach (var item in calculoSeguroDto.ListVeiculo) { taxaRisco = (item.Valor * 5) / (2 * item.Valor); premioRisco = (taxaRisco * item.Valor) / 100; premioPuro = premioRisco * (1 + (MARGEM_SEGURANCA / 100)); SeguroVeiculoDto seguroVeiculoDto = new SeguroVeiculoDto { TaxaRisco = taxaRisco, PremioRisco = premioRisco, PremioPuro = premioPuro, PremioComercial = ((LUCRO * premioPuro) / 100) + premioPuro, SeguradoVeiculoId = calculoSeguroDto.Segurado.Id, DataCalculo = DateTime.Now }; //pesquisar se já existe seguro filters = new List <IFilter>(); filters.Add(new FilterObj { FilterName = "numerocpf", FilterValue = calculoSeguroDto.Segurado.NumeroCPF }); filters.Add(new FilterObj { FilterName = "codigoveiculo", FilterValue = item.Id }); _seguroVeiculoRepository.SetMethodSource("GetByFilter"); var seguriVeiculoExist = await _seguroVeiculoRepository.FetchWhere(filters); if (seguriVeiculoExist == null) { var seguroVeiculo = _mapper.Map <SeguroVeiculo>(seguroVeiculoDto); _seguroVeiculoRepository.SetMethodSource("Add"); segurosResult.Add(await _seguroVeiculoRepository.Insert(seguroVeiculo)); } else { var seguroVeiculo = _mapper.Map <SeguroVeiculo>(seguroVeiculoDto); seguroVeiculo.Id = seguriVeiculoExist.FirstOrDefault().Id; _seguroVeiculoRepository.SetMethodSource("Update"); segurosResult.Add(await _seguroVeiculoRepository.Update(seguroVeiculo, "Id")); } taxaRisco = 0; premioRisco = 0; premioPuro = 0; } return(segurosResult); } catch (Exception ex) { throw ex; } }