예제 #1
0
        public ICommandResult Handle(CriarAgendamentoCommand command)
        {
            if (command.Valid() == false)
            {
                return(new GenericoAgendamentoCommandResult(false, "Ops Algo errado Aconteceu!", command.Notifications));
            }

            Agendamento Agendamento = new Agendamento(command.ClienteId, command.Observacao);

            if (Agendamento == null)
            {
                return(new GenericoAgendamentoCommandResult(false, "Não exite nenhum Agendamento com essa Id!", command.Notifications));
            }

            if (command.Procedimentos == null)
            {
                return(new GenericoAgendamentoCommandResult(false, "Não pode fazer um agendamento sem procedimentos!", command.Notifications));
            }

            var Cliente = _clienteRepository.BuscarClienteId(command.ClienteId);

            if (Cliente == null)
            {
                return(new GenericoAgendamentoCommandResult(false, "Não pode fazer um agendamento sem cliente!", command.Notifications));
            }

            Agendamento.AdicionarClienteId(Cliente.Id);

            foreach (var item in command.Procedimentos)
            {
                Agendamento.AdicionarProcedimento(item);
            }

            Agendamento.InserirObservacao(command.Observacao);


            _agendamentoRepository.Salvar(Agendamento);

            return(new GenericoAgendamentoCommandResult(true, "Pagamento Agendado com Sucesso!", Agendamento));
        }
 public GenericoAgendamentoCommandResult CriarAGendamento([FromBody] CriarAgendamentoCommand command, [FromServices] AgendamentoHandler handler)
 {
     return((GenericoAgendamentoCommandResult)handler.Handle(command));
 }