public void Cadastrar(GrupoCorredorArmazenagem grupoCorredorArmazenagem)
        {
            var _grupoCorredorArmazenagemPorCorredor = _unitOfWork.GrupoCorredorArmazenagemRepository.BuscarPorCorredor(grupoCorredorArmazenagem.IdEmpresa, grupoCorredorArmazenagem.CorredorInicial, grupoCorredorArmazenagem.CorredorFinal, grupoCorredorArmazenagem.IdPontoArmazenagem);

            ValidaCorredores(grupoCorredorArmazenagem.CorredorInicial, grupoCorredorArmazenagem.CorredorFinal);

            if (_grupoCorredorArmazenagemPorCorredor != null)
            {
                throw new BusinessException("O intervalo de corredores já foi cadastrado para o ponto de armazenagem informado.");
            }

            var listGrupoCorredorArmazenagem = _unitOfWork.GrupoCorredorArmazenagemRepository
                                               .BuscarPorEmpresaEPontoArmazenagem(grupoCorredorArmazenagem.IdEmpresa, grupoCorredorArmazenagem.IdPontoArmazenagem);

            if (IntevaloSobrepostos(listGrupoCorredorArmazenagem, grupoCorredorArmazenagem.CorredorInicial, grupoCorredorArmazenagem.CorredorFinal))
            {
                throw new BusinessException("Não é permitido cadastro de intervalo de corredores sobrepostos para um mesmo ponto de armazenagem.");
            }

            var _grupoCorredorArmazenagemPorImpressora = _unitOfWork.GrupoCorredorArmazenagemRepository.BuscarPorImpressora(grupoCorredorArmazenagem.IdEmpresa, grupoCorredorArmazenagem.CorredorInicial,
                                                                                                                            grupoCorredorArmazenagem.CorredorFinal, grupoCorredorArmazenagem.IdImpressora);

            if (_grupoCorredorArmazenagemPorImpressora != null)
            {
                throw new BusinessException("Existem corredores no intervalo informado com impressora configurada.");
            }

            _unitOfWork.GrupoCorredorArmazenagemRepository.Add(grupoCorredorArmazenagem);
            _unitOfWork.SaveChanges();
        }
        public void Editar(GrupoCorredorArmazenagem grupoCorredorArmazenagem, long idEmpresaUsuarioLogado)
        {
            var grupoCorredorArmazenagemAntigo = GetCorredorImpressoraById(grupoCorredorArmazenagem.IdGrupoCorredorArmazenagem);

            if (grupoCorredorArmazenagemAntigo == null)
            {
                throw new BusinessException("Corredor x impressora não encontrado");
            }

            if (grupoCorredorArmazenagemAntigo.IdEmpresa != idEmpresaUsuarioLogado)
            {
                throw new BusinessException("Usuário não tem permissão para editar o corredor x imprressora");
            }

            ValidaCorredores(grupoCorredorArmazenagem.CorredorInicial, grupoCorredorArmazenagem.CorredorFinal);

            var _grupoCorredorArmazenagemPorCorredor = _unitOfWork.GrupoCorredorArmazenagemRepository.BuscarPorCorredor(idEmpresaUsuarioLogado, grupoCorredorArmazenagem.CorredorInicial,
                                                                                                                        grupoCorredorArmazenagem.CorredorFinal, grupoCorredorArmazenagem.IdPontoArmazenagem);

            if (_grupoCorredorArmazenagemPorCorredor != null && _grupoCorredorArmazenagemPorCorredor.IdGrupoCorredorArmazenagem != grupoCorredorArmazenagem.IdGrupoCorredorArmazenagem)
            {
                throw new BusinessException("O intervalo de corredores já foi cadastrado para o ponto de armazenagem informado.");
            }

            var listGrupoCorredorArmazenagem = _unitOfWork.GrupoCorredorArmazenagemRepository.BuscarPorEmpresaEPontoArmazenagem(grupoCorredorArmazenagemAntigo.IdEmpresa, grupoCorredorArmazenagemAntigo.IdPontoArmazenagem);

            if (IntevaloSobrepostos(listGrupoCorredorArmazenagem.Where(gca => gca.IdGrupoCorredorArmazenagem != grupoCorredorArmazenagem.IdGrupoCorredorArmazenagem).ToList(), grupoCorredorArmazenagem.CorredorInicial, grupoCorredorArmazenagem.CorredorFinal))
            {
                throw new BusinessException("Não é permitido cadastro de intervalo de corredores sobrepostos para um mesmo ponto de armazenagem.");
            }

            var _grupoCorredorArmazenagemPorImpressora = _unitOfWork.GrupoCorredorArmazenagemRepository.BuscarPorImpressora(idEmpresaUsuarioLogado, grupoCorredorArmazenagem.CorredorInicial, grupoCorredorArmazenagem.CorredorFinal, grupoCorredorArmazenagem.IdImpressora);

            if (_grupoCorredorArmazenagemPorImpressora != null && _grupoCorredorArmazenagemPorImpressora.IdGrupoCorredorArmazenagem != grupoCorredorArmazenagem.IdGrupoCorredorArmazenagem)
            {
                throw new BusinessException("Existem corredores no intervalo informado com impressora configurada.");
            }

            grupoCorredorArmazenagemAntigo.IdImpressora       = grupoCorredorArmazenagem.IdImpressora;
            grupoCorredorArmazenagemAntigo.IdPontoArmazenagem = grupoCorredorArmazenagem.IdPontoArmazenagem;
            grupoCorredorArmazenagemAntigo.CorredorInicial    = grupoCorredorArmazenagem.CorredorInicial;
            grupoCorredorArmazenagemAntigo.CorredorFinal      = grupoCorredorArmazenagem.CorredorFinal;
            grupoCorredorArmazenagemAntigo.Ativo = grupoCorredorArmazenagem.Ativo;

            _unitOfWork.GrupoCorredorArmazenagemRepository.Update(grupoCorredorArmazenagemAntigo);
            _unitOfWork.SaveChanges();
        }