public ActionResult Nuevo(Guid id, string RFC, string RazonSocial, string CURP, bool Persona,
                                  string RegimenFiscal, string contraseña, string RegistroPatronal, string RfcPatronOrigen,
                                  string LugarExpedicion, string ClaveProdServs)
        {
            try
            {
                byte[]   cer      = null;
                byte[]   llave    = null;
                byte[]   logo     = null;
                string   PathLogo = "";
                Usuarios usuario  = db.Usuarios.Where(x => x.Usuario == User.Identity.Name).FirstOrDefault();
                foreach (string file in Request.Files)
                {
                    var fileContent = Request.Files[file];
                    if (fileContent != null && fileContent.ContentLength > 0)
                    {
                        var stream   = fileContent.InputStream;
                        var fileName = Path.GetFileName(fileContent.FileName);
                        if (file.Contains("llave"))
                        {
                            llave = new byte[fileContent.ContentLength];
                            llave = StreamHelper.ReadToEnd(fileContent.InputStream);
                        }
                        if (file.Contains("certificado"))
                        {
                            cer = new byte[fileContent.ContentLength];
                            cer = StreamHelper.ReadToEnd(fileContent.InputStream);
                        }
                        if (file.Contains("logo"))
                        {
                            logo = new byte[fileContent.ContentLength];
                            logo = StreamHelper.ReadToEnd(fileContent.InputStream);
                            Guid NombreLogo = Guid.NewGuid();
                            PathLogo = Server.MapPath("~/Images/Certificados/" + NombreLogo + fileContent.ContentType);
                            System.IO.File.WriteAllBytes(PathLogo, logo);
                        }
                    }
                }
                X509Certificate2 Certificado = new X509Certificate2(cer);
                if (Certificado.NotBefore > DateTime.Now)
                {
                    return(Json(new { error = "error", Message = "Todavia no Puedes Faturar hasra el " + Certificado.NotBefore.Day + "/" + Certificado.NotBefore.Month + "/" + Certificado.NotBefore.Year }, JsonRequestBehavior.AllowGet));
                }
                else if (Certificado.NotAfter < DateTime.Now)
                {
                    return(Json(new { error = "error", Message = "Ya se ha caducado el certificado" }, JsonRequestBehavior.AllowGet));
                }
                List <GetPAC_Result> pac = db.GetPAC(null, 0).ToList();
                bool exist = false;
                foreach (var item in pac)
                {
                    if (item.RFC == RFC)
                    {
                        exist = true;
                        id    = item.Id;
                    }
                }
                if (!exist)
                {
                    db.InsertPAC(id, RFC, RFC, RFC + "-010", RazonSocial, CURP,
                                 Persona, llave, cer, contraseña, RegimenFiscal,
                                 RegistroPatronal, RfcPatronOrigen, PathLogo, LugarExpedicion, Certificado.NotBefore,
                                 Certificado.NotAfter, usuario.Id, DateTime.Now, true);
                }
                else
                {
                    db.UpdatePAC(id, RFC, RFC, RFC + "-010", RazonSocial, CURP,
                                 Persona, llave, cer, contraseña, RegimenFiscal,
                                 RegistroPatronal, RfcPatronOrigen, logo, LugarExpedicion, Certificado.NotBefore,
                                 Certificado.NotAfter, true);
                }

                foreach (string claveServProd in ClaveProdServs.Split(','))
                {
                    db.InsertClaveProdServPorPAC(Guid.NewGuid(), id, claveServProd, usuario.Id, DateTime.Now);
                }
                string PATH = "~/Certificados/" + RFC;
                if (!System.IO.Directory.Exists(Server.MapPath(PATH)))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(PATH));
                }
                if (!System.IO.Directory.Exists(Server.MapPath("~/Facturas/" + RFC)))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath("~/Facturas/" + RFC));
                }
                System.IO.Directory.CreateDirectory(Server.MapPath("~/Facturas/" + RFC + "/Cancelaciones"));
                System.IO.Directory.CreateDirectory(Server.MapPath("~/Facturas/" + RFC + "/Facturas"));
                System.IO.Directory.CreateDirectory(Server.MapPath("~/Facturas/" + RFC + "/Nominas"));
                System.IO.File.WriteAllBytes(Server.MapPath(PATH + "/" + RFC + ".cer"), cer);
                System.IO.File.WriteAllBytes(Server.MapPath(PATH + "/" + RFC + ".key"), llave);

                /*WsEnrola.Service1SoapClient obj = new WsEnrola.Service1SoapClient();
                 * WsEnrola.WSEnrolaResponse etc = new WsEnrola.WSEnrolaResponse();
                 * etc = obj.AgregarUsuario("ABG1512109U1", "ABG1512109U1", "ABG1512109U1-010", RFC,RFC, RFC + "-010", RazonSocial,"", WsEnrola.TipoUsuario.Cliente);*/
                /*if (etc.Estado == 0) {
                 *  obj.AgregarTimbres("ABG1512109U1", "ABG1512109U1", "ABG1512109U1-010", RFC, RFC, 10);*/
                return(Json(new { error = "none", id = id }, JsonRequestBehavior.AllowGet));

                /*} else if (etc.Estado==309) {
                 *  return Json(new { error = "none",id= id }, JsonRequestBehavior.AllowGet);
                 * }
                 * else
                 *  return Json(new { error = "Error", Message = etc.MensajeDeError }, JsonRequestBehavior.AllowGet);*/
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { error = ex.InnerException, Message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }