Ejemplo n.º 1
0
        public JsonResult Submit(string name, string email)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //Check user info in database

                    var data = StayUpToDateData.GetByEmail(email);

                    if (data != null)
                    {
                        return(Json(new { code = "0" }, JsonRequestBehavior.AllowGet));
                    }

                    //Save subscriber infor into database
                    var subscriberInfo = new StayUpToDateData {
                        Name = name, Email = email
                    };
                    subscriberInfo.Save();

                    return(Json(new { code = "1" }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { fail = "failed" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { fail = "failed" }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 2
0
        private DataTable DataForNewsLetter()
        {
            var dataTable = new DataTable();
            var CSV_ROW   = "{0}*{1}";

            foreach (string column in _newsletterFormColumn)
            {
                var dcol = new DataColumn(column, typeof(String));
                dataTable.Columns.Add(dcol);
            }
            var contacts = StayUpToDateData.GetAll();

            foreach (var contact in contacts)
            {
                DataRow dr = dataTable.NewRow();
                int     i  = 0;

                try
                {
                    string data = string.Format(CSV_ROW, contact.Name,
                                                contact.Email);
                    char[]   delimiter = { '*' };
                    string[] rows      = data.Split(delimiter);
                    while (i < _newsletterFormColumn.Count())
                    {
                        dr[_newsletterFormColumn[i]] = rows[i];
                        i++;
                    }
                }
                catch (Exception ex)
                {
                    string what = "ever";
                }

                dataTable.Rows.Add(dr);
            }
            return(dataTable);
        }