public List <FuncionarioServico> FindByIdServico(int id)
        {
            var servicos = _repoFuncionarioServico.FindByIdServico(id);

            if (servicos.Count < 1)
            {
                return(null);
            }

            return(servicos);
        }
Esempio n. 2
0
        public Agendamento Create(Agendamento agendamento)
        {
            var cliente = _repoCliente.FindById(agendamento.ClienteId);
            var servico = _repoServico.FindById(agendamento.ServicoId);

            if (cliente == null || servico == null)
            {
                return(null);
            }

            // Adiciona o funcionário que realiza o serviço solicitado.
            var funcionarioServico = _repoFuncionarioServico.FindByIdServico(servico.Id).FirstOrDefault();

            if (funcionarioServico == null)
            {
                return(null);
            }

            agendamento.Funcionario = funcionarioServico.Funcionario;
            agendamento.DataTermino = agendamento.Data.Value.AddMinutes(servico.MinutosParaExecucao);

            var agenda = _repoAgendamento.FindAll();

            if (agenda.Count < 1)
            {
                return(_repoAgendamento.Create(agendamento));
            }

            DateTime dataTerminoParaAgendar = agendamento.Data.Value.AddMinutes(servico.MinutosParaExecucao);

            if (agenda.Any(a => a.DataTermino >= agendamento.Data && a.Data <= dataTerminoParaAgendar &&
                           a.Funcionario == funcionarioServico.Funcionario))
            {
                return(null);
            }

            return(_repoAgendamento.Create(agendamento));
        }