Ejemplo n.º 1
0
        private void GerarRomaneio(CentroDistribuicao cd)
        {
            var notasFiscais = _dbContext.NotasFiscais.Where(nf =>
            nf.Status == Status.Novo &&
            nf.Destinatario.Rota.CentroDistribuicao.CentroDistribuicaoId == cd.CentroDistribuicaoId
              ).ToList();

              SaveRomaneio(cd.ToString(), notasFiscais);
        }
        //public ActionResult Franqueados()
        //{
        //  var excel = new ExcelQueryFactory(HttpRuntime.AppDomainAppPath + "\\App_Data\\franqueados.xlsx");
        //  var franqueados = from c in excel.Worksheet()
        //                    select c;
        //  foreach (var franqueado in franqueados)
        //  {
        //    var rota = GetRota(franqueado["CD"], franqueado["ROTA"]);
        //    var cnpj = franqueado["CNPJ"];
        //    var franq = db.Postos.Where(p => p.CNPJ == cnpj).SingleOrDefault();
        //    if (franq == null)
        //    {
        //      franq = new Posto
        //      {
        //        CNPJ = cnpj,
        //        Nome = franqueado["RAZAOSOCIAL"],
        //        Endereco = new Endereco
        //        {
        //          Bairro = franqueado["BAIRRO"],
        //          Logradouro = franqueado["ENDERECO"],
        //          Cep = franqueado["CEP"],
        //          Municipio = franqueado["MUNICIPIO"],
        //          UF = franqueado["UF"],
        //          Pais = "Brasil",
        //          Numero = "não informado",
        //        },
        //      };
        //    }
        //    franq.Rota = rota;
        //    db.Postos.Add(franq);
        //    db.SaveChanges();
        //  }
        //  return View();
        //}
        //private Rota GetRota(string cdNome, string rotaNome)
        //{
        //  var centroDistribuicao = GetCD(cdNome);
        //  return
        //    db.Rotas.Where(r => r.Nome == rotaNome && r.CentroDistribuicaoId == centroDistribuicao.CentroDistribuicaoId).FirstOrDefault() ??
        //    new Rota {
        //      Nome = rotaNome,
        //      CentroDistribuicao = centroDistribuicao
        //    };
        //}
        private CentroDistribuicao GetCD(string cdNome)
        {
            var cdt = db.CentroDistribuicoes.Where(cd => cd.Nome == cdNome).FirstOrDefault();
              if (cdt == null)
              {
            cdt = new CentroDistribuicao
            {
              Nome = cdNome
            };

            db.CentroDistribuicoes.Add(cdt);
            db.SaveChanges();
              }
              return cdt;
        }