public ActionResult Renseigner(int?page) { using (WakilRecouvContext WakilContext = new WakilRecouvContext()) { using (UnitOfWork UOW = new UnitOfWork(WakilContext)) { LettreService lettreService = new LettreService(UOW); LotService LotService = new LotService(UOW); EmployeService EmployeService = new EmployeService(UOW); List <Lettre> lettreList = lettreService.GetAll().OrderByDescending(f => f.DateExtrait).ToList(); ViewData["list"] = new SelectList(NumLotListForDropDown(LotService), "Value", "Text"); ViewBag.AgentList = new SelectList(AgentListForDropDown(EmployeService), "Value", "Text"); ViewBag.total = lettreList.Count(); int pageSize = 10; int pageNumber = (page ?? 1); return(View(lettreList.ToPagedList(pageNumber, pageSize))); } } }
public ActionResult ExtraireLettreAction(string numLot, string debutDate, string finDate, string agent) { using (WakilRecouvContext WakilContext = new WakilRecouvContext()) { using (UnitOfWork UOW = new UnitOfWork(WakilContext)) { FormulaireService FormulaireService = new FormulaireService(UOW); AffectationService AffectationService = new AffectationService(UOW); LotService LotService = new LotService(UOW); LettreService lettreService = new LettreService(UOW); EmployeService EmployeService = new EmployeService(UOW); ViewData["list"] = new SelectList(NumLotListForDropDown(LotService), "Value", "Text"); ViewBag.AgentList = new SelectList(AgentListForDropDown(EmployeService), "Value", "Text"); string lettreDir = GetFolderNameForLettre(); DateTime startDate = DateTime.Parse(debutDate); DateTime endDate = DateTime.Parse(finDate); if (!Directory.Exists(lettreDir)) { Directory.CreateDirectory(lettreDir); } string lettreDirList = Directory.GetDirectories(lettreDir).Length + 1 + "_" + ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds() + ""; string dirLettre = ""; if (!Directory.Exists(lettreDir + "/" + lettreDirList)) { Directory.CreateDirectory(lettreDir + "/" + lettreDirList); dirLettre = lettreDir + "/" + lettreDirList; } List <LettreContent> lettreJoinedList = new List <LettreContent>(); if (numLot == "0") { lettreJoinedList = (from f in FormulaireService.GetAll() join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId join l in LotService.GetAll() on a.LotId equals l.LotId where (f.TraiteLe.Date >= startDate.Date && f.TraiteLe.Date <= endDate.Date) && (f.EtatClient == Note.FAUX_NUM || f.EtatClient == Note.NRP || f.EtatClient == Note.INJOIGNABLE) && lettreIsTrue(FormulaireService, a.AffectationId) select new LettreContent { NumLot = l.NumLot, Adresse = l.Adresse, NomClient = l.NomClient, Agence = l.DescIndustry, Compte = l.Compte }).ToList(); if (int.Parse(agent) != 0) { lettreJoinedList = (from f in FormulaireService.GetAll() join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId join l in LotService.GetAll() on a.LotId equals l.LotId where (f.TraiteLe.Date >= startDate.Date && f.TraiteLe.Date <= endDate.Date) && (f.EtatClient == Note.FAUX_NUM || f.EtatClient == Note.NRP || f.EtatClient == Note.INJOIGNABLE) && lettreIsTrue(FormulaireService, a.AffectationId) && a.EmployeId == int.Parse(agent) select new LettreContent { NumLot = l.NumLot, Adresse = l.Adresse, NomClient = l.NomClient, Agence = l.DescIndustry, Compte = l.Compte }).ToList(); } else { lettreJoinedList = (from f in FormulaireService.GetAll() join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId join l in LotService.GetAll() on a.LotId equals l.LotId where (f.TraiteLe.Date >= startDate.Date && f.TraiteLe.Date <= endDate.Date) && (f.EtatClient == Note.FAUX_NUM || f.EtatClient == Note.NRP || f.EtatClient == Note.INJOIGNABLE) && lettreIsTrue(FormulaireService, a.AffectationId) select new LettreContent { NumLot = l.NumLot, Adresse = l.Adresse, NomClient = l.NomClient, Agence = l.DescIndustry, Compte = l.Compte }).ToList(); } } else { if (int.Parse(agent) != 0) { lettreJoinedList = (from f in FormulaireService.GetAll() join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId join l in LotService.GetAll() on a.LotId equals l.LotId where (f.TraiteLe.Date >= startDate.Date && f.TraiteLe.Date <= endDate.Date) && (f.EtatClient == Note.FAUX_NUM || f.EtatClient == Note.NRP || f.EtatClient == Note.INJOIGNABLE) && lettreIsTrue(FormulaireService, a.AffectationId) && (l.NumLot.Equals(numLot)) && a.EmployeId == int.Parse(agent) select new LettreContent { NumLot = l.NumLot, Adresse = l.Adresse, NomClient = l.NomClient, Agence = l.DescIndustry, Compte = l.Compte, IdAgent = a.EmployeId + "" }).ToList(); } else { lettreJoinedList = (from f in FormulaireService.GetAll() join a in AffectationService.GetAll() on f.AffectationId equals a.AffectationId join l in LotService.GetAll() on a.LotId equals l.LotId where (f.TraiteLe.Date >= startDate.Date && f.TraiteLe.Date <= endDate.Date) && (f.EtatClient == Note.FAUX_NUM || f.EtatClient == Note.NRP || f.EtatClient == Note.INJOIGNABLE) && lettreIsTrue(FormulaireService, a.AffectationId) && (l.NumLot.Equals(numLot)) select new LettreContent { NumLot = l.NumLot, Adresse = l.Adresse, NomClient = l.NomClient, Agence = l.DescIndustry, Compte = l.Compte, IdAgent = a.EmployeId + "" }).ToList(); } } int x = 0; ViewBag.total = lettreJoinedList.Count(); foreach (LettreContent lc in lettreJoinedList) { string path = dirLettre + "/" + x + "_" + "lettre" + "_" + lc.Compte + ".docx"; if (Directory.Exists(dirLettre)) { GenerateWordForLettre(path, lc); } ViewData["currClient"] = x; x++; } string zipPath = zipFolderResult(dirLettre); string adressExcelPath = Server.MapPath("~/Uploads/Lettre/0_Result/") + DateTime.Now.ToString("dd.MM.yyyy") + "_" + Path.GetFileName(dirLettre) + ".xlsx"; GenerateExcelForLettre(GenerateDatatableFromJoinedListForLettre(lettreJoinedList), adressExcelPath); Lettre lettre = new Lettre { DateDeb = startDate.Date, DateFin = endDate.Date, DateExtrait = DateTime.Now, LettrePathName = zipPath, LettreAdressPathName = Path.GetFileName(adressExcelPath) }; lettreService.Add(lettre); lettreService.Commit(); return(RedirectToAction("Renseigner", new { page = 1 })); } } }