public void Editar(long id, DateTime data, long idServico, long idCliente, long idFuncionario, string guidUsuarioAgendou)
        {
            try
            {
                ClienteModel cliente = svCliente.Find(idCliente);
                if (cliente.IsNull())
                {
                    throw new AtendimentoInvalidoException("Cliente inválido.");
                }

                ServicoModel servico = svServico.Find(idServico);
                if (servico.IsNull())
                {
                    throw new AtendimentoInvalidoException("Serviço inválido.");
                }

                FuncionarioModel funcionario = svFuncionario.Find(idFuncionario);
                if (funcionario.IsNull())
                {
                    throw new AtendimentoInvalidoException("Funcionário inválido.");
                }

                if (funcionario.Servicos.IsNotNull())
                {
                    if (!funcionario.Servicos.ToList().Exists(s => s.Id == servico.Id))
                    {
                        throw new AtendimentoInvalidoException("Este Funcionário não presta este serviço.");
                    }
                }

                AtendimentoModel agendamentoCadastrado = _repository.GetAtendimento(cliente.Id, servico.Id, funcionario.Id, data.DateHourMinute());
                if (agendamentoCadastrado.IsNotNull() && agendamentoCadastrado.Id != id)
                {
                    throw new AtendimentoInvalidoException("Já existe um atendimento para este cliente com este funcionário neste horário.");
                }

                AtendimentoModel a = _repository.Find(id);
                if (a.IsNull())
                {
                    throw new AtendimentoInvalidoException($"Atendimento {id} não encontrado.");
                }

                a.Editar(data.DateHourMinute(), cliente, servico, funcionario, guidUsuarioAgendou, servico.Preco);

                _repository.Save(a);
            }
            catch (DomainException dEx)
            {
                Logger.Log.Warn(dEx);
                throw;
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex);
                throw;
            }
        }
        public void Agendar(long idEmpresa, DateTime data, long idServico, long idCliente, long idFuncionario, string guidUsuarioAgendou)
        {
            try
            {
                //if (data < DateTime.Now.FirstHourOfDay().AddMonths(-1))
                //    { throw new AtendimentoInvalidoException("Data inválido."); }

                //if (data.DateHourMinute() < DateTime.Now.DateHourMinute())
                //{ throw new AtendimentoInvalidoException("Data inválida, não é possível realizar um agendamento para o passado."); }

                ClienteModel cliente = svCliente.Find(idCliente);
                if (cliente.IsNull())
                {
                    throw new AtendimentoInvalidoException("Cliente inválido.");
                }

                ServicoModel servico = svServico.Find(idServico);
                if (servico.IsNull())
                {
                    throw new AtendimentoInvalidoException("Serviço inválido.");
                }

                FuncionarioModel funcionario = svFuncionario.Find(idFuncionario);
                if (funcionario.IsNull())
                {
                    throw new AtendimentoInvalidoException("Funcionário inválido.");
                }

                AtendimentoModel agendamentoCadastrado = _repository.GetAtendimento(cliente.Id, servico.Id, funcionario.Id, data.DateHourMinute());
                if (agendamentoCadastrado.IsNotNull())
                {
                    throw new AtendimentoInvalidoException("Já existe um atendimento para este cliente com este funcionário neste horário.");
                }

                EmpresaModel empresa = svEmpresa.Find(idEmpresa);

                AtendimentoModel a = new AtendimentoModel(empresa, data.DateHourMinute(), cliente, servico, funcionario, guidUsuarioAgendou, servico.Preco);

                _repository.Save(a);
            }
            catch (DomainException dEx)
            {
                Logger.Log.Warn(dEx);
                throw;
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex);
                throw;
            }
        }
Beispiel #3
0
        internal void Fill(DateTime datahora, ClienteModel cliente, ServicoModel servico, FuncionarioModel funcionario, string guidUsuarioAgendou, decimal precoServico)
        {
            if (datahora.IsNull())
            {
                throw new AtendimentoInvalidoException("Data inválida.");
            }
            if (cliente.IsNull())
            {
                throw new AtendimentoInvalidoException("Cliente inválido.");
            }
            if (servico.IsNull())
            {
                throw new AtendimentoInvalidoException("Serviço inválido.");
            }
            if (funcionario.IsNull())
            {
                throw new AtendimentoInvalidoException("Funcionário inválido.");
            }
            if (guidUsuarioAgendou.IsNull())
            {
                throw new AtendimentoInvalidoException("Usuário que agendou inválido.");
            }
            if (precoServico <= 0)
            {
                throw new AtendimentoInvalidoException("Um Atendimento não pode ter valor zero.");
            }

            DataHora           = datahora;
            Cliente            = null;
            IdCliente          = cliente.Id;
            Servico            = null;
            IdServico          = servico.Id;
            Funcionario        = null;
            IdFuncionario      = funcionario.Id;
            GuidUsuarioAgendou = guidUsuarioAgendou;
            Valor = precoServico;
        }