public IHttpActionResult SetKeystores(KeystoresInfo data) { try { string Error = ""; Company currentComp = ((EInvoiceContext)FX.Context.FXContext.Current).CurrentCompany; IKeyStoresService keystoreSrv = IoC.Resolve <IKeyStoresService>(); KeyStores keyStore = keystoreSrv.GetKeyStoreByComID(currentComp.id).FirstOrDefault(); if (keyStore == null) { keyStore = new KeyStores(); } keyStore.ComID = currentComp.id; keyStore.SerialCert = data.CertSerial; keyStore.Password = data.PassWord; keyStore.Type = 4; X509Certificate2 x509Cert = new X509Certificate2(Convert.FromBase64String(data.CertData)); Certificate cert = new Certificate(); cert.ComID = currentComp.id; cert.Cert = data.CertData; cert.SerialCert = data.CertSerial; cert.Used = true; cert.ValidFrom = x509Cert.NotBefore; cert.ValidTo = x509Cert.NotAfter; if (keyStore.Id > 0) { if (keystoreSrv.UpdateKeyStore(keyStore, cert, out Error)) { return(Ok("OK")); } } else if (keystoreSrv.CreateKeyStore(keyStore, cert, out Error)) { return(Ok("OK")); } return(Ok("ERROR:1")); } catch (Exception ex) { return(NotFound()); } }
public ActionResult ViewKeyStores() { IKeyStoresService _ikeySer = IoC.Resolve <IKeyStoresService>(); Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; ICertificateService _cerSVC = IoC.Resolve <ICertificateService>(); try { KeyStores oKeyStores = _ikeySer.Query.Where(a => a.ComID == _currentCompany.id).SingleOrDefault(); if (oKeyStores == null) { Messages.AddErrorFlashMessage("Chưa đăng ký chữ ký số, liên hệ nhà cung cấp để được hỗ trợ."); return(RedirectToAction("Index", "Home")); } if (oKeyStores.Type == 2 || oKeyStores.KeyStoresOf == 1) { Certificate cer = new Certificate(); cer.id = oKeyStores.Id; cer.ComID = oKeyStores.ComID; cer.SerialCert = oKeyStores.SerialCert; cer.Cert = ""; cer.OrganizationCA = ""; cer.OwnCA = ""; cer.ValidFrom = new DateTime(); cer.ValidTo = new DateTime(); return(View(cer)); } Certificate cert = (from c in _cerSVC.Query where c.ComID == _currentCompany.id && oKeyStores.SerialCert == c.SerialCert select c).SingleOrDefault(); if (cert == null) { Messages.AddErrorFlashMessage("Bạn vẫn chưa cấu hình keyStore"); return(RedirectToAction("Index", "Home")); } return(View(cert)); } catch (Exception ex) { Messages.AddErrorFlashMessage("Bạn vẫn chưa cấu hình keyStore"); log.Error(" ViewKeyStores -" + ex.Message); return(RedirectToAction("Index", "Home")); } }