Exemplo n.º 1
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 (NewsletterEntities db = new NewsletterEntities())
                {
                    var signup = new SignUp();
                    signup.FirstName    = firstName;
                    signup.LastName     = lastName;
                    signup.EmailAddress = emailAddress;

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

                return(View("Success"));
            }
        }
 // GET: Admin
 public ActionResult Index()
 {
     using (NewsletterEntities db = new NewsletterEntities())
     {
         //both filters work, currently redundant but left them to show both examples
         //var signups = db.SignUps.Where(x => x.Removed == null);
         //this is linq
         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));
     }
 }
Exemplo n.º 3
0
        // GET: Admin
        public ActionResult Index()
        {
            using (NewsletterEntities db = new NewsletterEntities())
            {
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();

                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));
            }
        }
Exemplo n.º 4
0
        protected void BuildServiceConfiguration(Campaign newsletter)
        {
            List <CampaignProperty> campaignProperties;
            List <VendorProperty>   vendorProperties;

            //  Initialize and add key properties with default values.
            _propertyList = new Dictionary <string, string>();
            _ds           = new NewsletterEntities();

            //  Add key campaign information
            _propertyList.Add(CAMPAIGN_ID, newsletter.CampaignID.ToString());
            _propertyList.Add(CAMPAIGN_NAME, newsletter.Name);

            //  Get the vendor property settings for passed in newsletter campaign.
            vendorProperties = (from vp in _ds.VendorProperties
                                where vp.VendorID == newsletter.VendorID
                                select vp).ToList();

            //  Iterate through vendor properties and add to internal property
            //  dictonary.
            foreach (VendorProperty vp in vendorProperties)
            {
                _propertyList.Add(vp.PropertyName, vp.PropertyValue);
            }

            //  Get the property settings for passed in newsletter campaign.
            campaignProperties = (from cp in _ds.CampaignProperties
                                  where cp.CampaignID == newsletter.CampaignID
                                  select cp).ToList();

            //  Iterate through campaign properties and add to internal
            //  property dictonary.
            foreach (CampaignProperty cp in campaignProperties)
            {
                _propertyList.Add(cp.PropertyName, cp.PropertyValue);
            }
        }
Exemplo n.º 5
0
        // GET: Admin
        public ActionResult Index()
        {
            //using to acces the db
            using (NewsletterEntities db = new NewsletterEntities())
            {
                // prop SignUps (in Newsletter.Context.cs) that represents all of the records in our db
                //var signups = db.SignUps.Where(x => x.Removed == null).ToList();
                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));
            }
        }
Exemplo n.º 6
0
 public SessionManager(NewsletterEntities context)
 {
     this.context = context;
 }
Exemplo n.º 7
0
        // GET: Admin
        public ActionResult Index()
        {
            {//NOTE: BELOW IS THE ADO.NET SYNTAX ORIGINALLY USED ; NOW REPLACED BY ENTITY FRAMEWORK SYNTAX (but left the ADO.NET code for learning purposes):END NOTE
             /*going to use ADO.NET to get all the signups off the database to display for the Admin */
             //string queryString = @"SELECT Id, FirstName, LastName, EmailAddress, SocialSecurityNumber FROM SignUps";
             //List<SignUp> signups = new List<SignUp>();/*creating a List of type SignUp and namining the new list "signups"; each item in the list will be referred to as a "signup"*/

                //using (SqlConnection connection = new SqlConnection(connectionString))/*using the sql connection string to get into the database*/
                //{
                //    SqlCommand command = new SqlCommand(queryString, connection);/*passing the queryString (the instructions for the database request) and the connection string info to get SignUps Table information to display for the Admin off of the database*/

                //    connection.Open();

                //    SqlDataReader reader = command.ExecuteReader();/*read the data in the table*/

                //    while (reader.Read())
                //    {
                //        /*here we mapped the data from the SignUp table in the database to the signups list we are creating*/
                //        var signup = new SignUp();/*make a new object called "signup* of type "SignUp"(this is our model class "SignUp") made up of the information that we are reading from the database*/
                //        signup.Id = Convert.ToInt32(reader["Id"]);/*we have to convert the information gathered off the database to a format that c sharp can understand*/

                //        signup.FirstName = reader["FirstName"].ToString();
                //        signup.LastName = reader["LastName"].ToString();
                //        signup.EmailAddress = reader["EmailAddress"].ToString();
                //        signup.SocialSecurityNumber = reader["SocialSecurityNumber"].ToString();

                //        signups.Add(signup);/*we are adding this new information(signup.FirstName, signup.LastName, etc....) to our new "signups" list*/

                //    }
                //}

                //ENTITY FRAMEWORK SYNTAX STARTS HERE:
                //(Note:Entity Framework serves as a wrapper for condensed ADO.NET code)

                using (NewsletterEntities db = new NewsletterEntities()) //using entity syntax to instanciate the NewsletterEntities object that gives us access to the database through the Entity Framework
                {                                                        //Alternate way to display only the signed up people***the "WHERE" part below is LINQ syntax and we are looking for the signups that the value of removed is null))
                                                                         // var signups = db.SignUps.Where(x => x.Removed == null).ToList();  // created the variable "signups"; which is equal to db.SignUps(which is the DbSet of the SignUps Table in the database;
                                                                         //and therefore, giving us access to all of the records in the database table)
                                                                         //NOTE: See comments in Newsletter.Context.cs for further explaination of DbSet
                    var signups = (from c in db.SignUps
                                   where c.Removed == null
                                   select c).ToList();

                    //NOTE:This part of the code was used in the ADO.NET Syntax (as is), as well as here in the Entity Framework Syntax(from this line all the way down to the return view line of code)
                    //here we are mapping the values from the signup model(signup) to the signup view model(signupVm)

                    var signupVms = new List <SignUpVm>();//create a new list of view models


                    foreach (var signup in signups)//loop through the database info that has been mapped to a model
                    {
                        var signupVm = new SignUpVm();
                        /*here we map our properties from the signups list we created to the signupVm list we created to display to the ViewModel*/
                        /*we are using the ViewModel to display the info to the Admin User so that we can explicitly choose what data to show */
                        /* (for example: if you were needing to protect against exposure of private info (ie. social security numbers, */
                        /*credit card info., birth date, medical diagnosis, account balance, etc.) that maybe contained in the data transferred fromm the database*/
                        signupVm.Id           = signup.Id;
                        signupVm.FirstName    = signup.FirstName;
                        signupVm.LastName     = signup.LastName;
                        signupVm.EmailAddress = signup.EmailAddress;

                        signupVms.Add(signupVm);//then adding the newly mapped values to the view model list
                    }

                    return(View(signupVms));//then passing this all to the View Model View!!!! Ta-Da!!!Thank you...thank you very much!!!! You're too kind...thank you.
                }
            }
        }
        public ActionResult SignUp(string firstName, string lastName, string emailAddress, DateTime dateOfBirth, int carYear, string carMake, string carModel, bool?dui, int tickets, bool?fullCoverage)
        {
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(emailAddress))
            {
                return(View("~/Views/Shared/Error.cshtml"));
            }
            else
            {
                int monthlytotal = 50;
                int age;
                using (NewsletterEntities db = new NewsletterEntities())
                {
                    var signup = new SignUps_();
                    signup.FirstName    = firstName;
                    signup.LastName     = lastName;
                    signup.EmailAddress = emailAddress;
                    signup.DateOfBirth  = dateOfBirth;
                    signup.Dui          = dui;
                    signup.FullCoverage = fullCoverage;
                    signup.CarMake      = carMake;
                    signup.CarYear      = carYear;
                    signup.Tickets      = tickets;
                    signup.CarModel     = carModel;


                    age = DateTime.Now.Year - dateOfBirth.Year;
                    if (DateTime.Now.DayOfYear < dateOfBirth.DayOfYear)
                    {
                        age = age - 1;
                    }

                    if (age < 25 && age > 18)
                    {
                        monthlytotal = monthlytotal + 25;
                    }
                    else if (age > 18)
                    {
                        monthlytotal = monthlytotal + 100;
                    }
                    else if (age > 100)
                    {
                        monthlytotal = monthlytotal + 25;
                    }
                    if (carYear < 2000 || carYear > 2015)
                    {
                        monthlytotal = monthlytotal + 25;
                    }
                    if (carMake == "Porsche")
                    {
                        monthlytotal = monthlytotal + 25;
                    }
                    if (carMake == "Porsche" && carModel == "911 Carrera")
                    {
                        monthlytotal = monthlytotal + 25;
                    }
                    monthlytotal = monthlytotal + (25 * tickets);

                    if (dui == true)
                    {
                        monthlytotal = Convert.ToInt32(monthlytotal * 1.25);
                    }
                    signup.MonthlyTotal = monthlytotal;
                    db.SignUps_.Add(signup);
                    db.SaveChanges();
                    return(View("TotalQuote", signup));
                }
            }
        }
Exemplo n.º 9
0
 public NewsletterStorefront(CustomerInfo customer)
 {
     _ds = new NewsletterEntities();
     Initialize();
     Customer = customer;
 }
Exemplo n.º 10
0
 public NewsletterStorefront()
 {
     _ds = new NewsletterEntities();
     Initialize();
     Customer = new CustomerInfo();
 }