Ejemplo n.º 1
0
        public ICommandResult HandlerCreate(CriarExperimentoCommand command)
        {
            try
            {
                AddNotifications(command.Notifications);
                command.Validated();

                //Validar os commands
                if (Invalid)
                {
                    return(new CommandResult(Notifications));
                }

                //Criar os VOs
                var nomeExperimento = new Nome(command.Nome);

                //Criar as entidades
                var experimento = new Experimento(nomeExperimento, command.QtdRepeticao);
                foreach (var tratamentoCommand in command.Tratamento)
                {
                    var tratamento = _tratamentoRepository.GetByIdTracking(Guid.Parse(tratamentoCommand.Id));
                    if (tratamento != null)
                    {
                        experimento.AddTratamento(new ExperimentoTramento(experimento, tratamento));
                    }
                }

                if (command.Status.Equals(ECommandStatus.Aberto))
                {
                    experimento.Arquivar();
                }
                else if (command.Status.Equals(ECommandStatus.EmAdamento))
                {
                    experimento.Gerar();
                }


                //Validar entidades e VOs
                AddNotifications(experimento.Notifications);
                if (Invalid)
                {
                    return(new CommandResult(Notifications));
                }

                //Persistir experimento
                _experimentoRepository.Save(experimento);
                //Retornar o resultado para a tela
                return(new CommandResult(new { Id = experimento.Id, Nome = experimento.Nome.ToString(), Status = experimento.Status }));
            }
            catch (Exception e)
            {
                return(new CommandResult(e));
            }
        }
        public async Task <ExperimentDto> Execute(ExperimentDto dilutionSampleDto)
        {
            Experimento experiment = ExperimentDtoMapToExperimento.Map(new Experimento(), dilutionSampleDto);

            if (experiment == null)
            {
                throw new AppError("Informe uma solicitação válida.");
            }
            _experimentRepository.Save(experiment);
            await _experimentRepository.Commit();

            return(dilutionSampleDto);
        }