Exemplo n.º 1
0
        public void Concluir(long id, decimal?valor)
        {
            try
            {
                AtendimentoModel a = _repository.Find(id);

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

                if (valor.IsNotNull())
                {
                    a.Concluir(valor.Value);
                }
                else
                {
                    a.Concluir(a.Valor);
                }

                _repository.Save(a);
            }
            catch (DomainException dEx)
            {
                Logger.Log.Warn(dEx);
                throw;
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex);
                throw;
            }
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
        public void Delete(long id)
        {
            try
            {
                AtendimentoModel a = _repository.Find(id);
                if (a.IsNull())
                {
                    throw new AtendimentoInvalidoException($"Atendimento {id} não encontrado.");
                }

                a.Deletar();
                _repository.Save(a);
            }
            catch (DomainException dEx)
            {
                Logger.Log.Warn(dEx);
                throw;
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex);
                throw;
            }
        }