/// <summary>
        /// actualiza un registro
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            try
            {
                using (var conexion = new DataModelFE())
                {
                    // se declara el objeto a insertar
                    ConfiguracionCorreo dato = new ConfiguracionCorreo();
                    //llena el objeto con los valores de la pantalla
                    dato.codigo = e.NewValues["codigo"] != null ? e.NewValues["codigo"].ToString() : null;

                    //busca el objeto
                    dato = conexion.ConfiguracionCorreo.Find(dato.codigo);

                    if (e.NewValues["password"] != null)
                    {
                        dato.password = e.NewValues["password"] != null?Ale5Util.Encriptar(e.NewValues["password"].ToString()) : null;
                    }

                    dato.codigo = e.NewValues["codigo"] != null ? e.NewValues["codigo"].ToString() : null;
                    dato.ssl    = e.NewValues["ssl"] != null ? e.NewValues["ssl"].ToString() : null;
                    dato.port   = e.NewValues["port"] != null ? e.NewValues["port"].ToString().ToUpper() : null;
                    dato.user   = e.NewValues["user"] != null ? e.NewValues["user"].ToString(): null;
                    dato.host   = e.NewValues["host"] != null ? e.NewValues["host"].ToString() : null;
                    dato.estado = e.NewValues["estado"].ToString();
                    dato.usuarioModificacion = Session["usuario"].ToString();
                    dato.fechaModificacion   = Date.DateTimeNow();

                    //modifica objeto
                    conexion.Entry(dato).State = EntityState.Modified;
                    conexion.SaveChanges();

                    //esto es para el manero del devexpress
                    e.Cancel = true;
                    this.ASPxGridView1.CancelEdit();
                    ((ASPxGridView)sender).JSProperties["cpUpdatedMessage"] = "Los datos se modificaron correctamente, puede continuar.";
                }
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);
                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(fullErrorMessage, ex.EntityValidationErrors);
            }
            catch (Exception ex)
            {
                throw new Exception(Utilidades.validarExepcionSQL(ex), ex.InnerException);
            }
            finally
            {
                //refescar los datos
                this.refreshData();
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="emisor">pasara buscar el proveedor de correo</param>
        /// <param name="destinatario">direccion de correo</param>
        /// <param name="asunto">asunto de correo</param>
        /// <param name="mensaje">contenido del correo</param>
        /// <param name="alias">nombre para enmascar el correo</param>
        /// <returns>TRUE envaido FALSE no eviado</returns>
        public static bool sendMail(string emisor, string destinatario, string asunto, string mensaje, string alias, List <string> cc)
        {
            try
            {
                using (var conexion = new DataModelFE())
                {
                    ConfiguracionCorreo mailConfig = conexion.ConfiguracionCorreo.Where(x => x.estado == Estado.ACTIVO.ToString() && x.codigo == emisor).FirstOrDefault();
                    if (mailConfig == null)
                    {
                        mailConfig = conexion.ConfiguracionCorreo.Where(x => x.estado == Estado.ACTIVO.ToString() && x.codigo == Usuario.USUARIO_AUTOMATICO).FirstOrDefault();
                    }

                    MailMessage correo = new MailMessage();
                    SmtpClient  smtp   = new SmtpClient();
                    correo.From = new MailAddress(mailConfig.user, alias);


                    if (string.IsNullOrWhiteSpace(destinatario))
                    {
                        correo.To.Add(cc[0]);
                    }
                    else
                    {
                        correo.To.Add(destinatario);
                    }

                    if (cc != null)
                    {
                        foreach (var item in cc)
                        {
                            correo.CC.Add(item);
                        }
                    }
                    //correo.Subject = String.Format("SPAM-LOW: {0}", asunto);
                    correo.Subject    = asunto;
                    correo.Body       = mensaje;
                    correo.Priority   = MailPriority.Normal;
                    correo.IsBodyHtml = true;
                    smtp.Credentials  = new NetworkCredential(mailConfig.user, Ale5Util.DesEncriptar(mailConfig.password));
                    smtp.Host         = mailConfig.host;
                    smtp.Port         = int.Parse(mailConfig.port);

                    if (Confirmacion.SI.ToString().Equals(mailConfig.ssl))
                    {
                        smtp.EnableSsl = true;
                    }
                    else
                    {
                        smtp.EnableSsl = false;
                    }

                    smtp.Send(correo);
                    correo.Dispose();
                }
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }