コード例 #1
0
        public async Task <ICommandResult> Handle(GerarMatriculaCommand command)
        {
            var matricula = new MicroServicosPoc.Matricula.Domain.Entities.Matricula(command.Cpf, true, command.IdUsuarioEmail);

            AddNotifications(matricula);

            if (await _matriculaRepository.CpfExiste(command.Cpf))
            {
                AddNotification("matricula.cpf", "Já existe matrícula com este CPF");
            }

            if (Invalid)
            {
                return(new GerarMatriculaCommandResult(false, "Inconsistências encontradas", Notifications));
            }

            await _matriculaRepository.Salvar(matricula);

            var matriculaQueryResult = await _matriculaRepository.ObterPorCpf(matricula.Cpf);

            return(new GerarMatriculaCommandResult(true, "Matricula inserida com sucesso!", matriculaQueryResult));
        }