public ActionResult CreateRPublish(Publish mPub, string PubInvoiceList) { IPublishService pubSrc = IoC.Resolve <IPublishService>(); ITaxAuthorityService taxSrv = IoC.Resolve <ITaxAuthorityService>(); ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); string message = ""; try { mPub.TaxAuthorityName = (from tax in taxSrv.Query where tax.Code == mPub.TaxAuthorityCode select tax.Name).FirstOrDefault(); JavaScriptSerializer jss = new JavaScriptSerializer(); IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); foreach (var it in lst) { IPublishInvoiceService pubinvSrv = IoC.Resolve <IPublishInvoiceService>(); string invSer = string.Format("{0}/{1}E", it.InvSerialPrefix, it.InvSerialSuffix); var old = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.StartDate > it.StartDate && p.ComId == _currentcompany.id).FirstOrDefault(); if (old != null) { Messages.AddErrorMessage(string.Format("Thông báo có ký hiệu {0}, phải có ngày bắt đầu sau ngày: {1}", old.InvSerial, old.StartDate.ToString("dd/MM/yyyy"))); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } var pub = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.FromNo == it.FromNo && p.ComId == _currentcompany.id); if (pub.Count() > 0) { Messages.AddErrorMessage(string.Format("Đã tồn tại giải hóa đơn tương ứng ký hiệu {0}", it.InvSerial)); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } } if (pubSrc.CreateNew(mPub, lst, out message) == true) { _currentcompany.IsUsed = true; _comSrv.Update(_currentcompany); _comSrv.CommitChanges(); StringBuilder InvInfo = new StringBuilder(); for (int i = 0; i < lst.Count; i++) { InvInfo.AppendFormat("{0};{1};{2};{3};{4}_", lst[i].RegisterID, lst[i].InvSerial, lst[i].Quantity, lst[i].FromNo, lst[i].ToNo); } log.Info("Create Publish by: " + HttpContext.User.Identity.Name + "|InvInfo:" + InvInfo.ToString()); Messages.AddFlashMessage("Tạo phát hành thành công!"); return(RedirectToAction("Index")); } else { log.Error("Create Publish:" + message); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!"); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } } catch (Exception ex) { JavaScriptSerializer jss = new JavaScriptSerializer(); IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList); log.Error(" CreateRPublish -" + ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } }