public Task<bool> sendMail() { bool resultado = false; try { MailMessage mail = new MailMessage(); mail.To.Add(this.To); mail.From = new MailAddress(this.From); mail.Subject = this.Subject; mail.Body = this.Body.ToString(); mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.live.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential ("*****@*****.**", "server_local1"); smtp.EnableSsl = true; ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; smtp.Send(mail); resultado = true; } catch (Exception ex) { SystemLog log = new SystemLog(); log.ErrorLog(ex.Message); } return Task.FromResult<bool>(resultado); }
public ActionResult Create([Bind(Include = "IdMembresia,TipoMembresia,FechaInicio,FechaFin")] Membresias membresias) { int idEspecialista = 0; Int32.TryParse(Request["IdEspecialista"], out idEspecialista); List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; if (ModelState.IsValid) { try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador")) { Especialistas especialista = db.Especialistas.Find(idEspecialista); Membresias membresiaAnt = especialista.Membresias; if (especialista != null) { membresias.Estado = true; especialista.Membresias = membresias; db.Membresias.Add(membresias); db.SaveChanges(); if (membresiaAnt != null) { db.Membresias.Remove(membresiaAnt); } db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Membresia registrado exitosamente." }); TempData["mensajes"] = lstMensajes; return RedirectToAction("Index"); } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Especialista no encontrado" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } return View(membresias); }
public ActionResult DeleteConfirmed(int id) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador")) { List<Especialistas> especialista = db.Especialistas.Include(m => m.Membresias).Where(m => m.Membresias.IdMembresia == id).ToList(); if (especialista.Count > 0) { especialista[0].Membresias = null; db.Entry(especialista[0]).State = EntityState.Modified; db.SaveChanges(); } Membresias membresias = db.Membresias.Find(id); db.Membresias.Remove(membresias); db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Membresia eliminada exitosamente." }); TempData["mensajes"] = lstMensajes; } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } return RedirectToAction("Index"); }
public ActionResult Edit_activar() { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; int idEspecialista = 0; Int32.TryParse(Request["idEspecialista"], out idEspecialista); bool estado = true; Boolean.TryParse(Request["estadoMembresia"], out estado); if (ModelState.IsValid) { try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador")) { Especialistas especialista = db.Especialistas.Find(idEspecialista); if (especialista != null) { if (especialista.Membresias != null) { especialista.Membresias.Estado = estado; db.Entry(especialista).State = EntityState.Modified; db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Membresia editada exitosamente." }); TempData["mensajes"] = lstMensajes; return RedirectToAction("GestionarSuscripcion","Administrador"); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "La membresia solicitada no se encontro" }); TempData["mensajes"] = lstMensajes; } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } return RedirectToAction("GestionarSuscripcion", "Administrador"); }
public ActionResult Create([Bind(Include = "IdCiudad,NombreCiudad")] Ciudades ciudades) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; if (ModelState.IsValid) { try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador")) { List<Ciudades> listado = db.Ciudades.Where(m => m.NombreCiudad.ToUpper() == ciudades.NombreCiudad.ToUpper()).ToList(); if (listado.Count == 0) { db.Ciudades.Add(ciudades); db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Ciudad registrada exitosamente." }); TempData["mensajes"] = lstMensajes; return RedirectToAction("Index"); } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Ya existe un registro con este nombre" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } return View(ciudades); }
public ActionResult Create_nuevo() { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; HttpPostedFileBase imagenM = (Request.Files.Count > 0) ? Request.Files[0] : null; string encodedData = string.Empty; string nombre = Request["Especialidad"]; if (imagenM != null) { MemoryStream target = new MemoryStream(); imagenM.InputStream.CopyTo(target); byte[] filebytes = target.ToArray(); if (filebytes.Length > 0) { string extension = Path.GetExtension(imagenM.FileName); encodedData = "data:image/" + extension.Replace(".", "") + ";base64,"; encodedData += Convert.ToBase64String(filebytes, Base64FormattingOptions.None); } } try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador")) { List<Especialidades> listado = db.Especialidades.Where(m => m.NombreEspecialidad.ToUpper() == nombre.ToUpper()).ToList(); if (listado.Count == 0) { Especialidades especialidad = new Especialidades { NombreEspecialidad = nombre, ImagenEspecialidad = encodedData, Estado=false }; db.Especialidades.Add(especialidad); db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Especialidad registrada exitosamente." }); TempData["mensajes"] = lstMensajes; } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Ya existe un registro con este nombre" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } //return View(); return RedirectToAction("index","Especialidad"); }
private object[] getExternalIp() { string externalIP = string.Empty; object[] infoIpAddress = null; try { externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/"); externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")) .Matches(externalIP)[0].ToString(); /*-----------------------------------------------------------------------------------------*/ WebRequest rssReq = WebRequest.Create("http://freegeoip.net/xml/" + externalIP); WebProxy px = new WebProxy("http://freegeoip.net/xml/" + externalIP, true); rssReq.Proxy = px; rssReq.Timeout = 5000; WebResponse rep = rssReq.GetResponse(); XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream()); DataSet ds = new DataSet(); ds.ReadXml(xtr); infoIpAddress = ds.Tables[0].Rows[0].ItemArray; } catch (Exception ex) { SystemLog log = new SystemLog(); log.ErrorLog(ex.Message); } return infoIpAddress; }
public ActionResult UpdateRestorePassword(string nueva_contrasena) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; try { string correo_logueo = (string)TempData["usuario_restore"]; if (!string.IsNullOrWhiteSpace(correo_logueo)) { List<Login> listado = db.Login.ToList().Where(m => m.UsuarioLogin == correo_logueo).ToList(); //Si el correo_electronico y la contrasena son validas subo a session la institucion if (listado != null) { if (listado.Count > 0) { listado[0].PasswordLogin= CifradoDatos.cifrarPassword(nueva_contrasena); db.SaveChanges(); //Obtengo ip y localizacion desde donde se realizo la modificacion object[] infoLogin = getExternalIp(); //Envio email confirmacion para habilitar el perfil StringBuilder bodyMail = new StringBuilder(); bodyMail.AppendLine("La contraseña para tu cuenta de usuario, " + listado[0].UsuarioLogin + " se ha cambiado recientemente." + "</br>"); bodyMail.AppendLine("Si la has cambiado tú, no necesitas realizar ninguna otra acción." + "</br>"); bodyMail.AppendLine("Si no la has cambiado tú, es posible que tu cuenta haya sido vulnerada. Para poder volver a iniciar sesión en tu cuenta, deberás restablecer la contraseña" + "</br>"); if (infoLogin != null) { bodyMail.AppendLine("Informacion Adicional:" + "</br>"); bodyMail.AppendLine("Pais:" + infoLogin[2].ToString() + "</br>"); bodyMail.AppendLine("Departamento:" + infoLogin[4].ToString() + "</br>"); bodyMail.AppendLine("Ciudad:" + infoLogin[5].ToString() + "</br>"); bodyMail.AppendLine("Ip Address:" + infoLogin[0].ToString() + "</br>"); } bodyMail.AppendLine("Fecha:" + DateTime.Now.ToString() + "</br>"); string subject = "Notificación modificación contraseña."; Mail mail = new Mail(correo_logueo, subject, bodyMail); if (mail.sendMail().Result) { lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificación", cuerpo = "Contraseña modificada exitosamente." }); TempData["mensajes"] = lstMensajes; TempData.Remove("usuario_restore"); } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Se produjo un error mientras se enviaba el correo. Correo invalido" }); } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No posee los permisos suficientes para realizar esta operación." }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No posee los permisos suficientes para realizar esta operación." }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No posee los permisos suficientes para realizar esta operación." }); TempData["mensajes"] = lstMensajes; } } catch (Exception ex) { SystemLog log = new SystemLog(); log.ErrorLog(ex.Message); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Se ha producido un error mientras se generaba el formulario" }); TempData["mensajes"] = lstMensajes; } TempData["mensajes"] = lstMensajes; ViewBag.lstMensajes = lstMensajes; return RedirectToAction("Index", "Home"); }
public Task<bool> sendMailAttachments(List<ArchivoAdjunto> listado) { bool resultado = false; try { MailMessage mail = new MailMessage(); mail.To.Add(this.To); mail.From = new MailAddress(this.From); mail.Subject = this.Subject; mail.Body = this.Body.ToString(); mail.IsBodyHtml = true; foreach (ArchivoAdjunto item in listado) { item.archivo.Position = 0; ContentType mContentType = new ContentType(item.tipo); //mContentType.MediaType = item.tipo; mContentType.Name = item.nombre; Attachment inline = new Attachment(item.archivo,mContentType); inline.ContentDisposition.Inline = true; inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline; mail.Attachments.Add(inline); } SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.live.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential ("*****@*****.**", "server_local1"); smtp.EnableSsl = true; ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; smtp.Send(mail); resultado = true; } catch (Exception ex) { SystemLog log = new SystemLog(); log.ErrorLog(ex.Message); } return Task.FromResult<bool>(resultado); }
/// <summary> /// Verifica que el correo este activo o exista. /// </summary> /// <returns></returns> public Task<List<Mensaje>> existeEmail() { List<Mensaje> lstMensajes = new List<Mensaje>(); try { string[] host = (this.To.Split('@')); string hostname = host[1]; IPHostEntry IPhst = Dns.Resolve(hostname); IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25); Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp); } catch (Exception ex) { SystemLog log = new SystemLog(); log.ErrorLog(ex.Message); lstMensajes.Add(new Mensaje{tipo="Error",titulo= "Error", cuerpo="El correo electronico " + this.To + " no existe o se encuentra inactivo."}); } return Task.FromResult<List<Mensaje>>(lstMensajes); }
public ActionResult Edit([Bind(Include = "IdEspecialista,NombreEsp,ApellidoEsp,FotoEsp,PaginaWebEsp,EmailEsp,CelularEsp,Calificacion,IdCurriculum,IdSuscripcion,IdLogin,Activo")] Especialistas especialista_aux) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; HttpPostedFileBase imagenM = (Request.Files.Count > 0) ? Request.Files[0] : null; string encodedData = string.Empty; if (ModelState.IsValid) { UsuarioAuth usuario = (UsuarioAuth)Session["usuario"]; List<Especialistas> especialista = db.Especialistas.ToList().Where(m => m.IdLogin == usuario.id).ToList(); if (especialista.Count > 0) { try { string tipoMembresia = Request["tipo-membresia"]; DateTime fecha_inicio; DateTime fecha_fin; DateTime.TryParse(Request["Modelo.Membresias.FechaInicio"], out fecha_inicio); DateTime.TryParse(Request["Modelo.Membresias.FechaFin"], out fecha_fin); string departamento = Request["Departamento-consultorio"]; int ciudad = 0; Int32.TryParse(Request["idCiudad"], out ciudad); int especialidad = 0; Int32.TryParse(Request["idEspecialidad"], out especialidad); string direccion = Request["calle-consultorio"]; string telefono = Request["telefono-consultorio"]; string latitud = Request["latitud"]; string longitud = Request["longitud"]; string contrasena1 = Request["contraseña-especialista"]; string contrasena2 = Request["confirmar-contraseña-especialista"]; Especialidades especialidad_Db = db.Especialidades.Find(especialidad); if (imagenM != null) { MemoryStream target = new MemoryStream(); imagenM.InputStream.CopyTo(target); byte[] filebytes = target.ToArray(); if (filebytes.Length > 0) { string extension = Path.GetExtension(imagenM.FileName); encodedData = "data:image/" + extension.Replace(".", "") + ";base64,"; encodedData += Convert.ToBase64String(filebytes, Base64FormattingOptions.None); } } if (!string.IsNullOrWhiteSpace(encodedData)) { especialista[0].FotoEsp = encodedData; } especialista[0].NombreEsp = especialista_aux.NombreEsp; especialista[0].ApellidoEsp = especialista_aux.ApellidoEsp; especialista[0].PaginaWebEsp = especialista_aux.PaginaWebEsp; especialista[0].CelularEsp = especialista_aux.CelularEsp; especialista[0].EmailEsp = especialista_aux.EmailEsp; especialista[0].Especialidades = especialidad_Db; especialista[0].Membresias.TipoMembresia = tipoMembresia; especialista[0].Membresias.FechaInicio = fecha_inicio; especialista[0].Membresias.FechaFin = fecha_fin; especialista[0].Direcciones.ToList()[0].Area = departamento; especialista[0].Direcciones.ToList()[0].IdCiudad = ciudad; especialista[0].Direcciones.ToList()[0].Calle = direccion; especialista[0].Direcciones.ToList()[0].TelefonoFijo = telefono; especialista[0].Direcciones.ToList()[0].Latitud = latitud; especialista[0].Direcciones.ToList()[0].Longitud = longitud; if (contrasena1.Equals(contrasena2) && !contrasena1.Equals("##########") && !string.IsNullOrWhiteSpace(contrasena1)) { especialista[0].Login.PasswordLogin = CifradoDatos.cifrarPassword(contrasena1); } db.Entry(especialista[0]).State = EntityState.Modified; db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Especialista editado exitosamente." }); TempData["mensajes"] = lstMensajes; return RedirectToAction("Index"); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Error" + ":" + "Ocurrio un error mientras se procesaba la solicitud" }); TempData["mensajes"] = lstMensajes; return View(); }
public ActionResult Create_nuevo() { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; HttpPostedFileBase imagenM = (Request.Files.Count > 0) ? Request.Files[0] : null; string encodedData = string.Empty; string nombre = Request["nombre_especialista"]; string apellidos = Request["apellido_especialista"]; string foto = Request["foto-especialista"]; string pagina = Request["pagina-especialista"]; string email = Request["email_especialista"]; string celular = Request["celular-especialista"]; int especialidad = 0; Int32.TryParse(Request["idEspecialidad"], out especialidad); string tipo_menbresia = Request["tipo_membresia"]; DateTime fecha_inicio; DateTime fecha_fin; DateTime.TryParse(Request["fecha_inicio_membresia"], out fecha_inicio); DateTime.TryParse(Request["fecha_fin_membresia"], out fecha_fin); string departamento = Request["Departamento-consultorio"]; int ciudad = 0; Int32.TryParse(Request["idCiudad"], out ciudad); string direccion = Request["calle_consultorio"]; string telefono = Request["telefono-consultorio"]; string latitud = Request["latitud"]; string longitud = Request["longitud"]; string contrasena1 = Request["contraseña_especialista"]; string contrasena2 = Request["confirmar_contraseña_especialista"]; if (!string.IsNullOrWhiteSpace(nombre) && !string.IsNullOrWhiteSpace(apellidos) && !string.IsNullOrWhiteSpace(email) && fecha_inicio != null && especialidad > 0 && fecha_fin != null && ciudad > 0 && !string.IsNullOrWhiteSpace(direccion) && !string.IsNullOrWhiteSpace(contrasena1) && !string.IsNullOrWhiteSpace(contrasena2)) { if (contrasena1.Equals(contrasena2)) { if (imagenM != null) { MemoryStream target = new MemoryStream(); imagenM.InputStream.CopyTo(target); byte[] filebytes = target.ToArray(); if (filebytes.Length > 0) { string extension = Path.GetExtension(imagenM.FileName); encodedData = "data:image/" + extension.Replace(".", "") + ";base64,"; encodedData += Convert.ToBase64String(filebytes, Base64FormattingOptions.None); } } try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador")) { List<TipoUsuario> tipo_usuario = db.TipoUsuario.ToList().Where(m => m.IdTipoUsuario == 3).ToList(); List<Especialidades> especialidades = db.Especialidades.ToList().Where(m => m.IdEspecialidad == especialidad).ToList(); if (tipo_usuario.Count > 0 && especialidades.Count > 0) { Membresias menbresia = new Membresias { TipoMembresia = tipo_menbresia, FechaInicio = fecha_inicio, FechaFin = fecha_fin }; Especialistas especialistas = new Especialistas { Activo = true, NombreEsp = nombre, ApellidoEsp = apellidos, PaginaWebEsp = pagina, CelularEsp = celular, EmailEsp = email, FotoEsp = encodedData, Especialidades = especialidades[0], Login = new Login { TipoUsuario = tipo_usuario[0], UsuarioLogin = email, PasswordLogin = CifradoDatos.cifrarPassword(contrasena1) }, IdSuscripcion = menbresia.IdMembresia }; Direcciones consultorio = new Direcciones { Calle = direccion, Ciudades = new Ciudades { IdCiudad = ciudad }, TelefonoFijo = telefono, Latitud = latitud, Longitud = longitud, Especialistas = especialistas }; db.Membresias.Add(menbresia); db.Especialistas.Add(especialistas); db.Direcciones.Add(consultorio); db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Especialista registrada exitosamente." }); TempData["mensajes"] = lstMensajes; } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Ocurrio un problema procesando la solicitud" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta accion, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta accion, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } } return RedirectToAction("InsertarEspecialista", "Administrador"); }
public JsonResult createChat(string nombre, string mensaje) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; UsuarioAuth usuario = (UsuarioAuth)Session["usuario"]; try { if (usuario != null) { if (usuario.rol == 1) { nombre = "ADMINISTRADOR"; } } if (!string.IsNullOrWhiteSpace(nombre) && !string.IsNullOrWhiteSpace(nombre)) { if (usuario != null) { if (usuario.rol == 1) { db.Chats.Add( new Chats { nombre = "ADMINISTRADOR", mensaje = mensaje, tipo_usuario = "ADMINISTRADOR", fecha_creacion = DateTime.Now } ); } } else { db.Chats.Add( new Chats { nombre = nombre, mensaje = mensaje, tipo_usuario = "USUARIO", fecha_creacion = DateTime.Now } ); } db.SaveChanges(); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } List<Chats> listado = db.Chats.OrderBy(m => m.id).Skip(Math.Max(0, db.Chats.ToList().Count - 20)).Take(10).ToList(); var resulSet = Json(new { listado }, "application/json; charset=utf-8", JsonRequestBehavior.AllowGet); resulSet.MaxJsonLength = 2147483647; return resulSet; }
public ActionResult SolicitarRestaurar() { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; string usuario_login = Request["email"]; if (!string.IsNullOrWhiteSpace(usuario_login)) { try { List<Login> listado = db.Login.ToList().Where(m => m.UsuarioLogin == usuario_login).ToList(); if (listado != null) { if (listado.Count > 0) { //Elimino solicitudes previas List<Restaurar_Pass> listado_ant = db.Restaurar_Pass.ToList().Where(m => m.correo_usuario == usuario_login).ToList(); if(listado_ant != null) { foreach(Restaurar_Pass obj in listado_ant) { db.Restaurar_Pass.Remove(obj); } } //Genero una nueva clave string clave = GetRandomString(15); //Genero una clave para el correo string clave_email = CifradoDatos.cifrarRSA(usuario_login); string clave_code = CifradoDatos.cifrarRSA(clave); db.Restaurar_Pass.Add(new Restaurar_Pass { correo_usuario = usuario_login, clave = clave }); db.SaveChanges(); //Creo corrreo con clave para enviar al usuario StringBuilder bodyMail = new StringBuilder(); bodyMail.AppendLine("Se ha activado la restauración de contraseña para tu cuenta de usuario, " + usuario_login + "</br>"); string informacionHost = serverInfoCurrent(); bodyMail.AppendLine("Dirijase al siguiente enlace para continuar con el proceso. " + "<a href=\"" + informacionHost + "/Home/ValidarRestaurar?tokenCorreo=" + clave_email + "&tokenClave=" + clave_code + "\"> Restaurar contraseña perfil. </a>" + "</br>"); bodyMail.AppendLine("Fecha:" + DateTime.Now.ToString() + "</br>"); string subject = "Notificación modificación contraseña."; Mail mail = new Mail(usuario_login, subject, bodyMail); if (mail.sendMail().Result) { lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificación", cuerpo = "Proceso finalizado exitosamente, verifique su correo electronico." }); } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Se produjo un error mientras se enviaba el correo. Correo invalido" }); } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "El usuario no existe o se encuentra bloqueado." }); } } else { lstMensajes.Add(new Mensaje{tipo="Error", titulo="Error", cuerpo="El usuario no existe o se encuentra bloqueado."}); } } catch (Exception ex) { SystemLog log = new SystemLog(); log.ErrorLog(ex.Message); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Se ha producido un error mientras se generaba el formulario" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "El usuario no existe o se encuentra bloqueado." }); } TempData["mensajes"] = lstMensajes; return RedirectToAction("Index", "Home"); }
public ActionResult Create([Bind(Include = "IdDireccion,Pais,Area,Calle,TelefonoFijo,Latitud,Longitud,IdEspecialista,IdCiudad")] Direcciones direcciones) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; if (ModelState.IsValid) { try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador") || admin.rolNombre.Equals("Vendedor")) { Especialistas especialista = db.Especialistas.Find(direcciones.IdEspecialista); Ciudades ciudad = db.Ciudades.Find(direcciones.IdCiudad); if (especialista != null && ciudad != null) { Direcciones nueva = new Direcciones { Calle = direcciones.Calle, Ciudades = ciudad, Especialistas = especialista, Latitud = direcciones.Latitud, Longitud = direcciones.Longitud, TelefonoFijo = direcciones.TelefonoFijo }; db.Direcciones.Add(nueva); db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Consultoria registrado exitosamente." }); TempData["mensajes"] = lstMensajes; return RedirectToAction("Index"); } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } return RedirectToAction("AgregarConsultorio", "Administrador"); }
public ActionResult ValidarRestaurar(string tokenCorreo, string tokenClave) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; if (!string.IsNullOrWhiteSpace(tokenCorreo) && !string.IsNullOrWhiteSpace(tokenClave)) { try { string correo = CifradoDatos.descifrarRSA(tokenCorreo); string clave = CifradoDatos.descifrarRSA(tokenClave); //Busco la entidad que cumpla con los parametros de correo y clave List<Restaurar_Pass> listado_ant = db.Restaurar_Pass.ToList().Where(m => m.correo_usuario == correo && m.clave==clave).ToList(); if (listado_ant != null) { if (listado_ant.Count > 0) { TempData["usuario_restore"] = correo; return RedirectToAction("Restaurar", "Home"); } } } catch (Exception ex) { SystemLog log = new SystemLog(); log.ErrorLog(ex.Message); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Se ha producido un error mientras se generaba el formulario" }); TempData["mensajes"] = lstMensajes; } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No posee los privilegios suficientes para ejecutar este proceso." }); TempData["mensajes"] = lstMensajes; return RedirectToAction("Index", "Home"); }
public ActionResult Edit([Bind(Include = "IdUsuario,NombreUsuario,ApellidoUsuario,EmailUsuario,CelularUsuario,Direccion,Activo,CedulaUsuario")] Usuarios usuarios) { string contrasena1 = Request["contrasena_vendedor"]; string contrasena2 = Request["confirmar_contrasena_vendedor"]; int idUsuario = 0; Int32.TryParse(Request["IdUsuario"], out idUsuario); List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; if (ModelState.IsValid) { try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador")) { List<Usuarios> vendedor = db.Usuarios.Include(m => m.Login).Where(m => m.IdUsuario == idUsuario).ToList(); if (vendedor.Count > 0) { vendedor[0].ApellidoUsuario = usuarios.ApellidoUsuario; vendedor[0].CedulaUsuario = usuarios.CedulaUsuario; vendedor[0].CelularUsuario = usuarios.CelularUsuario; vendedor[0].Direccion = usuarios.Direccion; vendedor[0].NombreUsuario = usuarios.NombreUsuario; vendedor[0].Activo = usuarios.Activo; if (contrasena1.Equals(contrasena2) && !string.IsNullOrWhiteSpace(contrasena1) && !contrasena1.Equals("##########")) { vendedor[0].Login.PasswordLogin = CifradoDatos.cifrarPassword(contrasena1); } if (!vendedor[0].EmailUsuario.Equals(usuarios.EmailUsuario)) { vendedor[0].Login.UsuarioLogin = usuarios.EmailUsuario; vendedor[0].EmailUsuario = usuarios.EmailUsuario; } db.Entry(vendedor[0]).State = EntityState.Modified; db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Vendedor editado exitosamente." }); TempData["mensajes"] = lstMensajes; return RedirectToAction("Index"); } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Usuario no encontrado, verfique los datos" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } return View(usuarios); }
public ActionResult Autenticacion() { string username = Request["user_name"]; string contrasena = Request["contrasena"]; List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; try { if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(contrasena)) { //Cifrado de la contrasena string password = CifradoDatos.cifrarPassword(contrasena); List<Login> listado = db.Login.ToList().Where(m => m.UsuarioLogin==username && m.PasswordLogin==password).ToList(); if (listado.Count > 0) { if ((listado[0].IdTipoUsuario == 1 || listado[0].IdTipoUsuario == 2) && listado[0].Usuarios.Count > 0) { Session["usuario"] = new UsuarioAuth { id = listado[0].IdLogin, nombre = listado[0].Usuarios.ToList()[0].NombreUsuario + " " + listado[0].Usuarios.ToList()[0].ApellidoUsuario, rol = listado[0].TipoUsuario.IdTipoUsuario, rolNombre = listado[0].TipoUsuario.NombreTipoUsuario }; if (listado[0].IdTipoUsuario == 1) { MvcApplication.admOnline = true; } lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Usuario autenticado exitosamente." }); } else if (listado[0].IdTipoUsuario == 3 && listado[0].Especialistas.Count > 0) { Session["usuario"] = new UsuarioAuth { id = listado[0].IdLogin, nombre = listado[0].Especialistas.ToList()[0].NombreEsp + " " + listado[0].Especialistas.ToList()[0].ApellidoEsp, rol = listado[0].TipoUsuario.IdTipoUsuario, rolNombre = listado[0].TipoUsuario.NombreTipoUsuario }; lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Usuario autenticado exitosamente." }); } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Usuario o contrasena invalidos, verifique" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Usuario o contrasena invalidos, verifique" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para procesar la solicitud." }); } } catch (Exception ex) { SystemLog log = new SystemLog(); log.ErrorLog(ex.Message); } TempData["mensajes"] = lstMensajes; return RedirectToAction("Index", "Home"); }
public ActionResult Create_nuevo() { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; string nombrev = Request["nombre_vendedor"]; string apellidosv = Request["apellido_vendedor"]; string emailv = Request["email_vendedor"]; string celularv = Request["celular-vendedor"]; string direccionv = Request["direccion-vendedor"]; string cedulav = Request["cedula-vendedor"]; string contrasena1v = Request["contrasena_vendedor"]; string contrasena2v = Request["confirmar_contrasena_vendedor"]; if (!string.IsNullOrWhiteSpace(nombrev) && !string.IsNullOrWhiteSpace(apellidosv) && !string.IsNullOrWhiteSpace(emailv) && !string.IsNullOrWhiteSpace(contrasena1v) && !string.IsNullOrWhiteSpace(contrasena2v)) { if (contrasena1v.Equals(contrasena2v)) { try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador")) { List<TipoUsuario> tipo_usuario = db.TipoUsuario.ToList().Where(m => m.IdTipoUsuario == 2).ToList(); if (tipo_usuario.Count > 0) { Usuarios usuario = new Usuarios { NombreUsuario = nombrev, ApellidoUsuario = apellidosv, EmailUsuario = emailv, CelularUsuario = celularv, Direccion = direccionv, CedulaUsuario = cedulav, Activo = true, Login = new Login { TipoUsuario = tipo_usuario[0], UsuarioLogin = emailv, PasswordLogin = CifradoDatos.cifrarPassword(contrasena1v) }, }; db.Usuarios.Add(usuario); db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Vendedor registrado exitosamente." }); TempData["mensajes"] = lstMensajes; } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Ocurrio un error mientras se procesaba la solicitud" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta accion, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta accion, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Las contraseñas no coinciden" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Algunos campos son requridos" }); TempData["mensajes"] = lstMensajes; } return RedirectToAction("IngresarComercial", "Administrador"); }
public ActionResult Edit([Bind(Include = "IdEspecialidad,NombreEspecialidad,ImagenEspecialidad")] Especialidades especialidades) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; HttpPostedFileBase imagenM = (Request.Files.Count > 0) ? Request.Files[0] : null; string encodedData = string.Empty; if (imagenM != null) { MemoryStream target = new MemoryStream(); imagenM.InputStream.CopyTo(target); byte[] filebytes = target.ToArray(); if (filebytes.Length > 0) { string extension = Path.GetExtension(imagenM.FileName); encodedData = "data:image/" + extension.Replace(".", "") + ";base64,"; encodedData += Convert.ToBase64String(filebytes, Base64FormattingOptions.None); } } if (ModelState.IsValid) { try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador")) { Especialidades especialidadDb = db.Especialidades.Find(especialidades.IdEspecialidad); if (especialidadDb != null) { if (!string.IsNullOrWhiteSpace(encodedData)) { especialidadDb.ImagenEspecialidad = encodedData; } especialidadDb.NombreEspecialidad = especialidades.NombreEspecialidad; db.Entry(especialidadDb).State = EntityState.Modified; db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Especialidad registrado exitosamente." }); TempData["mensajes"] = lstMensajes; return RedirectToAction("Index"); } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "Especialidad no encontrada" }); TempData["mensajes"] = lstMensajes; } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } return View(especialidades); }
public ActionResult Edit([Bind(Include = "IdMembresia,TipoMembresia,FechaInicio,FechaFin")] Membresias membresias) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; if (ModelState.IsValid) { try { UsuarioAuth admin = (UsuarioAuth)Session["usuario"]; if (admin != null) { if (admin.rolNombre.Equals("Administrador")) { Membresias membresiaDb = db.Membresias.Find(membresias.IdMembresia); if (membresiaDb != null) { membresiaDb.TipoMembresia = membresias.TipoMembresia; membresiaDb.FechaInicio = membresias.FechaInicio; membresiaDb.FechaFin = membresias.FechaFin; db.Entry(membresiaDb).State = EntityState.Modified; db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificacion", cuerpo = "Membresia editada exitosamente." }); TempData["mensajes"] = lstMensajes; return RedirectToAction("Index"); } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "La membresia solicitada no se encontro" }); TempData["mensajes"] = lstMensajes; } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta acción, inicie sesión" }); TempData["mensajes"] = lstMensajes; } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } return View(membresias); }
public ActionResult Create([Bind(Include = "IdArticulo,titulo,resumen,cuerpo,etiquetas,imagenArt")] Articulos articulos) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; if (ModelState.IsValid && Session["usuario"] != null) { HttpPostedFileBase imagenM = (Request.Files.Count > 0) ? Request.Files[0] : null; string encodedData = string.Empty; if (imagenM != null) { MemoryStream target = new MemoryStream(); imagenM.InputStream.CopyTo(target); byte[] filebytes = target.ToArray(); if (filebytes.Length > 0) { string extension = Path.GetExtension(imagenM.FileName); encodedData = "data:image/" + extension.Replace(".", "") + ";base64,"; encodedData += Convert.ToBase64String(filebytes, Base64FormattingOptions.None); } } try { UsuarioAuth usuario = (UsuarioAuth)Session["usuario"]; List<Especialistas> especialista = db.Especialistas.ToList().Where(m => m.IdLogin == usuario.id).ToList(); if (especialista.Count > 0) { articulos.Especialistas = especialista[0]; articulos.ImagenArt = encodedData; db.Articulos.Add(articulos); db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificación", cuerpo = "Articulo registrado exitosamente" }); TempData["mensajes"] = lstMensajes; return RedirectToAction("Index"); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios, inicie sesión" }); TempData["mensajes"] = lstMensajes; } TempData["mensajes"] = lstMensajes; ViewBag.IdEspecialista = new SelectList(db.Especialistas, "IdEspecialista", "NombreEsp", articulos.IdEspecialista); return View(articulos); }
public ActionResult Create([Bind(Include = "IdCV,ImagenCV,DescripcionCV")] Curriculums curriculums) { List<Mensaje> lstMensajes = (((List<Mensaje>)TempData["mensajes"]) == null) ? new List<Mensaje>() : (List<Mensaje>)TempData["mensajes"]; HttpPostedFileBase imagenM = (Request.Files.Count > 0) ? Request.Files[0] : null; string encodedData = string.Empty; if (imagenM != null) { MemoryStream target = new MemoryStream(); imagenM.InputStream.CopyTo(target); byte[] filebytes = target.ToArray(); if (filebytes.Length > 0) { string extension = Path.GetExtension(imagenM.FileName); encodedData = "data:image/" + extension.Replace(".", "") + ";base64,"; encodedData += Convert.ToBase64String(filebytes, Base64FormattingOptions.None); } } curriculums.ImagenCV = encodedData; if (ModelState.IsValid) { try { UsuarioAuth usuario = (UsuarioAuth)Session["usuario"]; if (usuario != null) { if (usuario.rolNombre.Equals("Especialista")) { List<Especialistas> especialistas = db.Especialistas.Where(m => m.IdLogin == usuario.id).ToList(); if (especialistas.Count > 0) { especialistas[0].Curriculums = curriculums; db.Entry(especialistas[0]).State = EntityState.Modified; db.SaveChanges(); lstMensajes.Add(new Mensaje { tipo = "Notificacion", titulo = "Notificación", cuerpo = "Curriculum registrado exitosamente" }); TempData["mensajes"] = lstMensajes; return RedirectToAction("Index"); } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta accion, inicie sesión" }); } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta accion, inicie sesión" }); } } else { lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = "No cuenta con privilegios para realizar esta accion, inicie sesión" }); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = error.PropertyName + ":" + error.ErrorMessage }); sb.AppendLine(); } } lstMensajes.Add(new Mensaje { tipo = "Error", titulo = "Error", cuerpo = sb.ToString() }); TempData["mensajes"] = lstMensajes; SystemLog log = new SystemLog(); log.ErrorLog(sb.ToString()); throw new Exception(sb.ToString()); } } TempData["mensajes"] = lstMensajes; return View(curriculums); }