示例#1
0
        public ActionResult AddCertificate(string id)
        {
            var item = new TaxpayerCertificate {
                TaxpayerId = id
            };

            return View (item);
        }
示例#2
0
        public ActionResult AddCertificate(string id)
        {
            var item = new TaxpayerCertificate {
                TaxpayerId = id
            };

            return(View(item));
        }
示例#3
0
        public ActionResult AddCertificate(TaxpayerCertificate item, IEnumerable<HttpPostedFileBase> files)
        {
            if (!ModelState.IsValid)
                return View (item);

            foreach (var file in files) {
                if (file != null && file.ContentLength > 0) {
                    var name = file.FileName.ToLower ();

                    if (name.EndsWith (".cer")) {
                        item.CertificateData = FileToBytes (file);
                    } else if (name.EndsWith (".key")) {
                        item.KeyData = FileToBytes (file);
                        item.KeyPassword = Encoding.UTF8.GetBytes (item.KeyPassword2);
                    }
                }
            }

            if (!CFDHelpers.PrivateKeyTest (item.KeyData, item.KeyPassword)) {
                ModelState.AddModelError ("KeyPassword", Resources.Validation_InvalidPassword);
                return View (item);
            }

            string sn = string.Empty;
            var cert = new X509Certificate2 ();
            cert.Import (item.CertificateData);

            foreach (var b in cert.GetSerialNumber ()) {
                sn = (char) b + sn;
            }

            item.Id = sn.PadLeft (20, '0');
            var entity = TaxpayerCertificate.Queryable.SingleOrDefault (x => x.Id == item.Id);

            if (entity == null) {
                entity = new TaxpayerCertificate ();
            }

            entity.Id = item.Id;
            entity.CertificateData = item.CertificateData;
            entity.KeyData = item.KeyData;
            entity.KeyPassword = item.KeyPassword;
            entity.NotBefore = cert.NotBefore;
            entity.NotAfter = cert.NotAfter;
            entity.Taxpayer = TaxpayerIssuer.Find (item.TaxpayerId);

            using (var scope = new TransactionScope ()) {
                foreach (var x in entity.Taxpayer.Certificates) {
                    x.IsActive = false;
                    x.Update ();
                }

                entity.IsActive = true;
                entity.SaveAndFlush ();
            }

            return RedirectToAction ("Details", new { id = item.TaxpayerId });
        }
示例#4
0
        public ActionResult AddCertificate(TaxpayerCertificate item, IEnumerable <HttpPostedFileBase> files)
        {
            if (!ModelState.IsValid)
            {
                return(View(item));
            }

            foreach (var file in files)
            {
                if (file != null && file.ContentLength > 0)
                {
                    var name = file.FileName.ToLower();

                    if (name.EndsWith(".cer"))
                    {
                        item.CertificateData = FileToBytes(file);
                    }
                    else if (name.EndsWith(".key"))
                    {
                        item.KeyData     = FileToBytes(file);
                        item.KeyPassword = Encoding.UTF8.GetBytes(item.KeyPassword2);
                    }
                }
            }

            if (!CFDHelpers.PrivateKeyTest(item.KeyData, item.KeyPassword))
            {
                ModelState.AddModelError("KeyPassword", Resources.Validation_InvalidPassword);
                return(View(item));
            }

            string sn   = string.Empty;
            var    cert = new X509Certificate2(item.CertificateData);

            foreach (var b in cert.GetSerialNumber())
            {
                sn = (char)b + sn;
            }

            item.Id = sn.PadLeft(20, '0');
            var entity = TaxpayerCertificate.Queryable.SingleOrDefault(x => x.Id == item.Id);

            if (entity == null)
            {
                entity = new TaxpayerCertificate();
            }

            entity.Id = item.Id;
            entity.CertificateData = item.CertificateData;
            entity.KeyData         = item.KeyData;
            entity.KeyPassword     = item.KeyPassword;
            entity.NotBefore       = cert.NotBefore;
            entity.NotAfter        = cert.NotAfter;
            entity.Taxpayer        = TaxpayerIssuer.Find(item.TaxpayerId);

            using (var scope = new TransactionScope()) {
                foreach (var x in entity.Taxpayer.Certificates)
                {
                    x.IsActive = false;
                    x.Update();
                }

                entity.IsActive = true;
                entity.SaveAndFlush();
            }

            return(RedirectToAction("Details", new { id = item.TaxpayerId }));
        }