示例#1
0
        public override string ToString()
        {
            var list = new List <string> {
                Id.ToString().ToLowerInvariant(),
                NumeroApolice.ToString().ToLowerInvariant(),
                IdentificacaoSegurado.ToLowerInvariant(),
                PlacaVeiculo.ToLowerInvariant(),
                ValorPremio.ToString().ToLowerInvariant()
            };

            return(string.Join(";", list));
        }
        public async Task <Unit> Handle(CriarApoliceCommand request, CancellationToken cancellationToken)
        {
            var segurado = await _seguradoRepository.Obter(request.CodigoSegurado);

            if (segurado == null)
            {
                await _mediatorHandler.RaiseAppEvent(this, "Não foi encontrado o segurado com o código informado.");

                return(Unit.Value);
            }

            var numeroApolice = NumeroApolice.Create(request.Apolice);
            var vigencia      = PeriodoVigencia.Create(request.InicioVigencia, request.FinalVigencia);
            var premioTotal   = PremioApolice.Create(request.PremioTotal);
            var premioLiquido = PremioApolice.Create(request.PremioLiquido);

            var result = Result.Combine(numeroApolice, vigencia, premioLiquido, premioTotal);

            if (result.IsFailure)
            {
                await _mediatorHandler.RaiseAppEvents(this, result.Errors);

                return(Unit.Value);
            }

            var apolice = new Apolice(
                numeroApolice.Value,
                vigencia.Value,
                premioTotal.Value,
                premioLiquido.Value,
                segurado.Codigo
                );

            await _apoliceRepository.Adicionar(apolice);

            await _apoliceRepository.Salvar();

            return(Unit.Value);
        }