public ActionResult Index(EInvoiceIndexModel model, int?page, int?Pagesize) { IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>(); Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; try { IList <string> lstpattern = _PubIn.LstByPattern(currentCom.id, 1); if (lstpattern.Count == 0) { Messages.AddErrorFlashMessage("Cần tạo thông báo phát hành."); return(RedirectToAction("Index", "Publish")); } if (model == null) { model = new EInvoiceIndexModel(); } model.Pattern = string.IsNullOrEmpty(model.Pattern) ? lstpattern[0] : model.Pattern; model.lstpattern = lstpattern; List <string> LstSerial = _PubIn.ListSerialByPattern(currentCom.id, model.Pattern, new int[] { 1, 2, 3 }).Distinct().ToList <string>(); model.lstserial = LstSerial; int defautPagesize = Pagesize.HasValue ? Convert.ToInt32(Pagesize) : 10; int currentPageIndex = page.HasValue ? page.Value - 1 : 0; int totalRecords = 0; IInvoiceService IInvSrv = InvServiceFactory.GetService(model.Pattern, currentCom.id); IList <IInvoice> lst; if (!model.InvNo.HasValue || model.InvNo == null) { DateTime?DateFrom = null; DateTime?DateTo = null; if (!string.IsNullOrWhiteSpace(model.FromDate)) { DateFrom = DateTime.ParseExact(model.FromDate, "dd/MM/yyyy", null); } if (!string.IsNullOrWhiteSpace(model.ToDate)) { DateTo = DateTime.ParseExact(model.ToDate, "dd/MM/yyyy", null); } if (DateFrom != null && DateTo != null && DateFrom > DateTo) { Messages.AddErrorMessage("Nhập đúng dữ liệu tìm kiếm theo ngày!"); DateFrom = DateTo = null; } lst = IInvSrv.SearchByCustomer(currentCom.id, model.Pattern, model.Serial, DateFrom, DateTo, (InvoiceStatus)model.Status, model.nameCus, model.code, model.CodeTax, (InvoiceType)model.typeInvoice, currentPageIndex, defautPagesize, out totalRecords); } else { lst = IInvSrv.GetListByNo(currentCom.id, model.Pattern, model.Serial, model.InvNo.Value); totalRecords = lst.Count(); } model.PageListINV = new PagedList <IInvoice>(lst, currentPageIndex, defautPagesize, totalRecords); int signPlugin = 0; if (currentCom.Config.Keys.Contains("SignPlugin")) { int.TryParse(currentCom.Config["SignPlugin"], out signPlugin); } model.SignPlugin = signPlugin; return(View(model)); } catch (UnAuthorizedException e) { log.Error(e); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!"); return(RedirectToAction("Index", "Home")); } catch (ArgumentException ex) { log.Error(ex); return(Redirect("/Home/PotentiallyError")); } catch (HttpRequestValidationException ex) { log.Error(ex); return(RedirectToAction("PotentiallyError", "Home")); } }