// GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities1 db = new NewsletterEntities1())
            {
                //var signups = (from c in db.SignUps
                //               where c.Removed == null
                //               select c).ToList();
                var signups   = db.SignUps.Where(x => x.Removed == null).ToList();
                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms));
            }

            //string queryString = @"SELECT Id, FirstName, LastName, EmailAddress, SocialSecurityNumber from SignUps";
            //List<NewsletterSignup> signups = new List<NewsletterSignup>();

            //using (SqlConnection connection = new SqlConnection(connectionString))
            //{
            //    SqlCommand command = new SqlCommand(queryString, connection);

            //    connection.Open();

            //    SqlDataReader reader = command.ExecuteReader();

            //    while (reader.Read())
            //    {
            //        var signup = new NewsletterSignup();
            //        signup.Id = Convert.ToInt32(reader["id"]);
            //        signup.FirstName = reader["FirstName"].ToString();
            //        signup.LastName = reader["LastName"].ToString();
            //        signup.EmailAddress = reader["EmailAddress"].ToString();
            //        signup.SocialSecurityNumber = reader["SocialSecurityNumber"].ToString();

            //        signups.Add(signup);
            //    }

            //}

            //var signupVms = new List<SignupVm>();
            //foreach (var signup in signups)
            //{
            //    var signupVm = new SignupVm();
            //    signupVm.FirstName = signup.FirstName;
            //    signupVm.LastName = signup.LastName;
            //    signupVm.EmailAddress = signup.EmailAddress;
            //    signupVms.Add(signupVm);

            //}

            //return View(signupVms);
        }
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities1 db = new NewsletterEntities1())
            {
                /////OPTION 1: Using lambda to filter unsubscribes out
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();

                ///OPTION 2: Using Linq to filter results
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();

                var signupVms = new List <SignUpVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignUpVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }

                return(View(signupVms));
            }
        }
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities1 db = new NewsletterEntities1())
            {
                //Lambda syntax
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();

                //Linq syntax
                var signups = (from c in db.SignUps
                               where c.Removed == null
                               select c).ToList();

                var signupVms = new List <SignupVm>();
                foreach (var signup in signups)
                {
                    var signupVm = new SignupVm();
                    signupVm.Id           = signup.Id;
                    signupVm.FirstName    = signup.FirstName;
                    signupVm.LastName     = signup.LastName;
                    signupVm.EmailAddress = signup.EmailAddress;
                    signupVms.Add(signupVm);
                }
                return(View(signupVms));
            }
        }
Beispiel #4
0
 public ActionResult Unsubscribe(int ID)
 {
     using (NewsletterEntities1 db = new NewsletterEntities1())
     {
         var signup = db.SignUps.Find(ID);
         signup.Removed = DateTime.Now;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Beispiel #5
0
 // GET: Admin
 public ActionResult Index()
 {
     using (NewsletterEntities1 db = new NewsletterEntities1())
     {
         /*var signups = db.SignUps.Where(x=> x.Removed==null).ToList()*/;                 //representes all of the records in our database (a list) filtered by subscribed
         var signups   = (from c in db.SignUps where c.Removed == null select c).ToList(); //same function as before but using Linq
         var signupVMs = new List <SignupVm>();
         foreach (var signup in signups)
         {
             var signupVm = new SignupVm();
             signupVm.Id           = signup.Id;
             signupVm.FirstName    = signup.FirstName;
             signupVm.LastName     = signup.LastName;
             signupVm.EmailAddress = signup.EmailAddress;
             signupVMs.Add(signupVm);
         }
         return(View(signupVMs));
     }
 }
        public ActionResult SignUp(string firstName, string lastName, string emailAddress)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                using (NewsletterEntities1 db = new NewsletterEntities1())
                {
                    var signup = new SignUp();
                    signup.FirstName    = firstName;
                    signup.LastName     = lastName;
                    signup.EmailAddress = emailAddress;

                    db.SignUps.Add(signup);
                    db.SaveChanges();
                }

                return(View("Success"));


                //string queryString = @"INSERT INTO SignUps (FirstName, LastName, EmailAddress) VALUES
                //                        (@FirstName, @LastName, @EmailAddress)";

                //using (SqlConnection connection = new SqlConnection(connectionString))
                //{
                //    SqlCommand command = new SqlCommand(queryString, connection);
                //    command.Parameters.Add("@FirstName", SqlDbType.VarChar);
                //    command.Parameters.Add("@LastName", SqlDbType.VarChar);
                //    command.Parameters.Add("@EmailAddress", SqlDbType.VarChar);

                //    command.Parameters["@FirstName"].Value = firstName;
                //    command.Parameters["@LastName"].Value = lastName;
                //    command.Parameters["@EmailAddress"].Value = emailAddress;

                //    connection.Open();
                //    command.ExecuteNonQuery();
                //    connection.Close();
                //}
            }
        }
Beispiel #7
0
        public ActionResult SignUp(string firstName, string lastName, string emailAddress)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                using (NewsletterEntities1 db = new NewsletterEntities1())
                {
                    var signup = new SignUp();
                    signup.FirstName    = firstName;
                    signup.LastName     = lastName;
                    signup.EmailAddress = emailAddress;

                    db.SignUps.Add(signup);
                    db.SaveChanges();
                }
                return(View("Success"));
            }
        }