public ActionResult InsertarPrimerusuario(IEnumerable <HttpPostedFileBase> files, FormCollection form) { LogicaUsuarios Logicausuarios = new LogicaUsuarios(); LogicaEmpresas LogicaEmpresas = new LogicaEmpresas(); LogicaRepresentantesLegales LogicaRepresentantesLegales = new LogicaRepresentantesLegales(); LogicaHome LogicaHome = new LogicaHome(); string FechaActual = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss"); try { if (Session["Registrando"] == null) { TempData["notice"] = "La sesión ha expirado."; return(RedirectToAction("Logout", "Home")); } Empresa = (CatEmpresas)Session["NuevoAcceso_Empresa"]; Representante = (CatRepresentantesLegales)Session["NuevoAcceso_Representante"]; string ClavePrivada = form["RL_ClavePrivada"]; string Validacion = MetodoGeneral.ValidarFIEL(files, ClavePrivada, Representante.RL_RFC); if (Validacion == "Validación exitosa") { CatEmpresas EmpresaSession = (CatEmpresas)Session["NuevoAcceso_Empresa"]; EmpresaSession.E_CompartirDatos = false; if (form["CompartirDatos"].Equals("2")) { EmpresaSession.E_CompartirDatos = true; } CatUsuarios UsuarioOperativoSession = (CatUsuarios)Session["NuevoAcceso_Usuario"]; //LogicaHome.L_InsertarRegistroSolicitud(EmpresaSession, Representante, UsuarioOperativoSession); string GUID = LogicaHome.L_InsertarRegistroSolicitud(Empresa, Representante, UsuarioOperativoSession); string ext = ""; X509Certificate2 CertificadoParaFirma = new X509Certificate2(); CatRepresentantesLegales NuevoRepresentante = (CatRepresentantesLegales)Session["NuevoAcceso_Representante"]; if (!Directory.Exists(@"C:\inetpub\RepositorioVER\Representantes\" + NuevoRepresentante.RL_IdRepresentanteLegal.ToString())) { DirectoryInfo di = Directory.CreateDirectory(@"C:\inetpub\RepositorioVER\Representantes\" + NuevoRepresentante.RL_IdRepresentanteLegal.ToString()); } int num_archivo = 0; foreach (string inputTagName in Request.Files) { HttpPostedFileBase file = Request.Files[num_archivo]; num_archivo = num_archivo + 1; ext = Path.GetExtension(file.FileName); if (ext != ".cer" && ext != ".key") { bool PdfValido = MetodoGeneral.ReadByteArrayFromFile(file); if ((file.ContentType.ToString().ToLower() == "application/pdf" && PdfValido) || file.ContentType.ToString().ToLower() == "application/x-zip-compressed") { string path = @"C:\inetpub\RepositorioVER\Representantes\" + NuevoRepresentante.RL_IdRepresentanteLegal.ToString() + "\\" + inputTagName + "_PDF_" + FechaActual + ext; using (Stream fs = file.InputStream) { fs.Flush(); fs.Position = 0; CertificadoParaFirma = MetodoGeneral.ObtenerCertificadoParaFirmar(files, ClavePrivada); MetodoGeneral.SignWithThisCert(CertificadoParaFirma, fs, path); } } } } TempData["notice"] = "Los datos han sido registrados exitosamente."; Session.Clear(); Session["TipoAlerta"] = "Correcto"; string target = @"C:\inetpub\RepositorioVER\Representantes\" + NuevoRepresentante.RL_IdRepresentanteLegal.ToString() + "\\" + "AcuseRegistroInversionista_PDF_" + FechaActual; CatRepresentantesLegales DatosRepresentante = LogicaRepresentantesLegales.L_DetallesRepresentanteLegal(NuevoRepresentante.RL_IdRepresentanteLegal); CatEmpresas DatosEmpresa = LogicaEmpresas.L_DetallesEmpresa(DatosRepresentante.RL_IdEmpresa); CrearAcuseRegistroInversionista(GUID, target, DatosEmpresa, DatosRepresentante); //Enviar acuse: new System.Threading.Tasks.Task(() => { try { string CorreoRepresentante = Representante.RL_CorreoElectronico; Representante.RL_FechaRegistro = DateTime.Now.ToString(); Representante.RL_Observaciones = "Solicitud de registro enviada"; //CatRepresentantesLegales DatosRepresentante = LogicaRepresentantesLegales.L_DetallesRepresentanteLegal(NuevoRepresentante.RL_IdRepresentanteLegal); //CatEmpresas DatosEmpresa = LogicaEmpresas.L_DetallesEmpresa(DatosRepresentante.RL_IdEmpresa); System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage("*****@*****.**", CorreoRepresentante); email.To.Add(new MailAddress(ConfigurationManager.AppSettings["CorreoAdministrador"].ToString())); email.Subject = "Acuse de registro"; email.Attachments.Add(new Attachment(target + ".pdf")); //Obtener la plantilla en HTML: string pathCorreo = ConfigurationManager.AppSettings["Html_AcuseRegistroENREL"].ToString(); string ContenidoCorreo = System.IO.File.ReadAllText(pathCorreo); //Reemplazar información string ContactoEmpresa = "Teléfono (" + DatosEmpresa.E_Lada + ") " + DatosEmpresa.E_TelefonoFijo.ToString(); string NombreRepresentante = DatosRepresentante.RL_Nombre + " " + DatosRepresentante.RL_PrimerApellido + " " + DatosRepresentante.RL_SegundoApellido; string ContactoRepresentanteLegal = "Teléfono (" + DatosRepresentante.RL_Lada + ") " + DatosRepresentante.RL_TelefonoFijo.ToString() + " Ext. " + DatosRepresentante.RL_ExtensionTelefonica + ", Teléfono móvil: " + DatosRepresentante.RL_TelefonoCelular; string EmpresaNumeroInterior = ""; try { EmpresaNumeroInterior = DatosEmpresa.E_NumeroInterior.ToString(); } catch { } string EmpresaCodigoPostal = ""; try { EmpresaCodigoPostal = DatosEmpresa.E_CodigoPostal.ToString(); } catch { } string RepresentanteNumeroInterior = ""; try { RepresentanteNumeroInterior = DatosRepresentante.RL_NumeroInterior.ToString(); } catch { } string RepresentanteCodigoPostal = ""; try { RepresentanteCodigoPostal = DatosRepresentante.RL_CodigoPostal.ToString(); } catch { } ContenidoCorreo = ContenidoCorreo.Replace("#NombreEmpresa#", DatosEmpresa.E_NombreComercial); ContenidoCorreo = ContenidoCorreo.Replace("#RFCEmpresa#", DatosEmpresa.E_RFC); ContenidoCorreo = ContenidoCorreo.Replace("#ContactoEmpresa#", ContactoEmpresa); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioEmpresaCalle#", DatosEmpresa.E_Calle); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioEmpresaNExterior#", DatosEmpresa.E_NumeroExterior.ToString()); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioEmpresaNInterior#", EmpresaNumeroInterior); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioEmpresaColonia#", DatosEmpresa.E_Colonia); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioEmpresaCP#", EmpresaCodigoPostal); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioEmpresaMunicipio#", DatosEmpresa.E_Municipio); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioEmpresaEstado#", DatosEmpresa.E_EntidadFederativa); ContenidoCorreo = ContenidoCorreo.Replace("#NombreRepresentanteLegal#", NombreRepresentante); ContenidoCorreo = ContenidoCorreo.Replace("#RFCRepresentanteLegal#", DatosRepresentante.RL_RFC); ContenidoCorreo = ContenidoCorreo.Replace("#ContactoRepresentanteLegal#", ContactoRepresentanteLegal); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioRepresentanteCalle#", DatosRepresentante.RL_Calle); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioRepresentanteNExterior#", DatosRepresentante.RL_NumeroExterior.ToString()); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioRepresentanteNInterior#", RepresentanteNumeroInterior); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioRepresentanteColonia#", DatosRepresentante.RL_Colonia); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioRepresentanteCP#", RepresentanteCodigoPostal); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioRepresentanteMunicipio#", DatosRepresentante.RL_Municipio); ContenidoCorreo = ContenidoCorreo.Replace("#DomicilioRepresentanteEstado#", DatosRepresentante.RL_EntidadFederativa); AlternateView htmlView = AlternateView.CreateAlternateViewFromString(ContenidoCorreo, null, "text/html"); //Obtener imágenes: LinkedResource Logotipo_SENER = new LinkedResource(ConfigurationManager.AppSettings["Logotipo_SENER"].ToString()); Logotipo_SENER.ContentId = "Logotipo_SENER"; htmlView.LinkedResources.Add(Logotipo_SENER); LinkedResource Logotipo_MEXICO = new LinkedResource(ConfigurationManager.AppSettings["Logotipo_MEXICO"].ToString()); Logotipo_MEXICO.ContentId = "Logotipo_MEXICO"; htmlView.LinkedResources.Add(Logotipo_MEXICO); email.AlternateViews.Add(htmlView); email.IsBodyHtml = true; email.Priority = MailPriority.High; SmtpClient smtp = new SmtpClient(); smtp.Host = "172.16.70.110"; smtp.Port = 25; smtp.EnableSsl = false; smtp.UseDefaultCredentials = false; smtp.Send(email); email.Dispose(); } catch (Exception ex) { MetodoGeneral.RegistroDeError(ex.Message, "Registro de inversionista: Quinto Paso - Envío de correo"); } }).Start(); return(View()); } else { TempData["notice"] = Validacion; Session["TipoAlerta"] = "Error"; MetodoGeneral.RegistroDeError(Validacion, "Registro de inversionista: Quinto Paso"); Representante = (CatRepresentantesLegales)Session["NuevoAcceso_Representante"]; ViewBag.RFCRepresentante = Representante.RL_RFC; if (Empresa.E_RFC.Length == 12) { ViewBag.MostrarDocumento = true; } else { ViewBag.MostrarDocumento = false; } return(View("DatosAcreditacion")); } } catch (Exception ex) { TempData["notice"] = ConfigurationManager.AppSettings["MensajeError"].ToString(); Session["TipoAlerta"] = "Error"; MetodoGeneral.RegistroDeError(ex.InnerException.ToString(), "Registro de inversionista: Quinto Paso"); if (Empresa.E_IdEmpresa > 0) { LogicaHome.L_EliminarIntentoRegistro(Empresa.E_IdEmpresa); } ViewBag.RFCRepresentante = Representante.RL_RFC; if (Empresa.E_RFC.Length == 12) { ViewBag.MostrarDocumento = true; } else { ViewBag.MostrarDocumento = false; } return(View("DatosAcreditacion")); } }