Example #1
0
        public bool Suscribe(NewsAddressee newsAddressee)
        {
            if (!IsValid(newsAddressee))
            {
                return(false);
            }

            //chequear existencia del correo
            NewsAddresseeMapper mapper    = new NewsAddresseeMapper();
            NewsAddressee       existence = mapper.Get(newsAddressee.Email);

            if (existence != null)
            {
                string errorDescription = "El suscriptor ya existe.";
                log.AddLogWarn("Save", errorDescription, this);
                AddError(new ResultBE(ResultBE.Type.FAIL, errorDescription));
                return(false);
            }

            newsAddressee.Active = true;
            newsAddressee.Singup = DateTime.Now;

            if (!mapper.Save(newsAddressee))
            {
                string errorDescription = "No se ha podido guardar el suscriptor.";
                log.AddLogCritical("Save", errorDescription, this);
                AddError(new ResultBE(ResultBE.Type.FAIL, errorDescription));
                return(false);
            }

            MailerHelper.SendNewsletterWelcome(newsAddressee);
            return(true);
        }
Example #2
0
        /// <summary>
        /// Valida que los datos para la suscripción estén completos.
        /// </summary>
        /// <param name="newsAddressee"></param>
        /// <returns></returns>
        private bool IsValid(NewsAddressee newsAddressee)
        {
            bool isValid = true;

            isValid &= VOnlyLetter(newsAddressee.Name, 1, 50, "Nombre", "IsValid");
            isValid &= VLetterNumbers(newsAddressee.Email, 7, 50, "Mail", "IsValid");
            isValid &= VLetterNumbers(newsAddressee.Categories, 1, 250, "Categorías", "IsValid");
            return(isValid);
        }
Example #3
0
        public bool Unsuscribe(NewsAddressee addressee)
        {
            Dal       dal   = new Dal();
            Hashtable table = new Hashtable();

            table.Add("@email", addressee.Email);
            table.Add("@active", addressee.Active);
            table.Add("@dropout", addressee.Dropout);
            return(dal.Write(table, "spModifyNewsAddressee") > 0);
        }
Example #4
0
        /// <summary>
        /// Envía la notificación de suscripción al newsletter
        /// </summary>
        /// <param name="addressee"></param>
        public static void SendNewsletterWelcome(NewsAddressee addressee)
        {
            string body = GetTemplate(
                addressee.Name,
                "Estás recibiendo este mail para recordarte que te has suscripto al newsletter." +
                Environment.NewLine + "Esperamos que lo disfrutes.",
                "http://localhost:50551/index.aspx"
                );

            Send("Suscripción al newsletter - Ubiquicity", body, new string[] { addressee.Email });
        }
Example #5
0
        public bool Save(NewsAddressee addressee)
        {
            Dal       dal   = new Dal();
            Hashtable table = new Hashtable();

            table.Add("@name", addressee.Name);
            table.Add("@mail", addressee.Email);
            table.Add("@active", addressee.Active);
            table.Add("@singup", addressee.Singup);
            table.Add("@categories", addressee.Categories);
            addressee.Id = dal.Write(table, "spWriteNewsAddressee");

            return(addressee.Id > 0);
        }
Example #6
0
        public NewsAddressee Get(string mail)
        {
            Dal           dal       = new Dal();
            Hashtable     table     = new Hashtable();
            NewsAddressee addressee = null;

            table.Add("@mail", mail);
            DataSet result = dal.Read(table, "spReadNewsAddressee");

            if (result != null && result.Tables[0].Rows.Count > 0)
            {
                addressee = ConvertToModel(result.Tables[0].Rows[0]);
            }
            return(addressee);
        }
Example #7
0
        /// <summary>
        /// Valida que los datos para ejecutar la desuscripción están completos.
        /// </summary>
        /// <param name="newsAddressee"></param>
        /// <param name="confirm"></param>
        /// <returns></returns>
        private bool IsValidForUnsuscribe(NewsAddressee newsAddressee, bool confirm)
        {
            bool isValid = true;

            isValid &= VLetterNumbers(newsAddressee.Email, 7, 50, "Mail", "IsValid");

            if (!confirm)
            {
                string errorDescription = "Debe confirmarse la acción de desuscripción.";
                log.AddLogWarn("IsValid", errorDescription, this);
                AddError(new ResultBE(ResultBE.Type.INCOMPLETE_FIELDS, errorDescription));
                isValid = false;
            }

            return(isValid);
        }
Example #8
0
        private NewsAddressee ConvertToModel(DataRow data)
        {
            NewsAddressee addressee = new NewsAddressee();

            addressee.Id         = int.Parse(data["id"].ToString());
            addressee.Name       = data["name"].ToString();
            addressee.Email      = data["email"].ToString();
            addressee.Singup     = Convert.ToDateTime(data["singup"]);
            addressee.Active     = Convert.ToBoolean(data["active"]);
            addressee.Categories = data["categories"].ToString();

            if (data["dropout"] != DBNull.Value)
            {
                addressee.Dropout = Convert.ToDateTime(data["dropout"]);
            }
            return(addressee);
        }
Example #9
0
        /// <summary>
        /// Ajecuta la suscripción
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSuscription_Click(object sender, EventArgs e)
        {
            try
            {
                //La estrategia consta de concatenar con @ los ids de las categorías para poder guardarlas un campo
                string categoryIds = "";
                foreach (ListItem item in checkCategory.Items)
                {
                    categoryIds += item.Selected ? item.Value + "@" : "";
                }

                NewsAddresseeManager manager   = new NewsAddresseeManager();
                NewsAddressee        addressee = new NewsAddressee();

                //TODO - deberían solicitarse mail y comprobación?
                addressee.Name  = nameSuscriptorInput.Value;
                addressee.Email = mailSuscriptorInput.Value;

                if (!String.IsNullOrEmpty(categoryIds))
                {
                    addressee.Categories = categoryIds.Substring(0, categoryIds.Length - 1);
                }

                bool success = manager.Suscribe(addressee);

                if (!success && manager.HasErrors)
                {
                    Alert.Show("Exception", manager.ErrorDescription);
                }
                else
                {
                    Alert.Show("Registro", "¡El registro fue un éxito! te enviamos un mail para recordarte sobre esto.");
                }
            }
            catch (Exception exception)
            {
                Alert.Show("Exception", exception.Message);
            }
        }
        protected void PerformUnsuscribe(object sender, EventArgs e)
        {
            try
            {
                NewsAddresseeManager naManager     = new NewsAddresseeManager();
                NewsAddressee        newsAddressee = new NewsAddressee();
                newsAddressee.Email = mailInput.Value;

                bool success = naManager.Unsuscribe(newsAddressee, chkConfirm.Checked);
                if (!success && naManager.HasErrors)
                {
                    ((front)Master).Alert.Show("Error", naManager.ErrorDescription);
                }
                else
                {
                    divForm.Visible           = false;
                    divSuccessMessage.Visible = true;
                }
            } catch (Exception exception)
            {
                ((front)Master).Alert.Show("Excepción", exception.Message);
            }
        }
Example #11
0
        /// <summary>
        /// Realiza la desuscripción del suscriptor.
        /// </summary>
        /// <param name="newsAddressee"></param>
        /// <param name="confirm"></param>
        /// <returns></returns>
        public bool Unsuscribe(NewsAddressee newsAddressee, bool confirm)
        {
            if (!IsValidForUnsuscribe(newsAddressee, confirm))
            {
                return(false);
            }

            NewsAddresseeMapper mapper = new NewsAddresseeMapper();

            newsAddressee.Active  = false;
            newsAddressee.Dropout = DateTime.Now;

            bool success = mapper.Unsuscribe(newsAddressee);

            if (!success)
            {
                string errorDescription = "No se ha podido ejecutar la desuscripción.";
                log.AddLogCritical("Unsuscribe", errorDescription, this);
                AddError(new ResultBE(ResultBE.Type.FAIL, errorDescription));
                return(false);
            }

            return(success);
        }