protected void btnLogin_Click(object sender, EventArgs e)
        {
            MarinaEntities1 db = new MarinaEntities1();

            lblStatus.Text = "";
            if (txtEmail2.Text != "" && txtPassword2.Text != "")
            {
                try
                {
                    var result = (from c in db.Customers
                                  where c.EMail == txtEmail2.Text
                                  select c).Single();

                    if (result.VerifyPassword(txtPassword2.Text))
                    {
                        Session["Authenticated"] = true;
                        Session["Username"]      = txtEmail2.Text;
                        Response.Redirect("LeaseSlip.aspx");
                    }
                    else
                    {
                        // Invalid password
                        lblStatus.Text = "Invalid username or password.";
                    }
                }
                catch (Exception)
                {
                    lblLoginStatus.Text = "No user exists, please register.";
                }
            }
            else
            {
                lblLoginStatus.Text = "All fields required";
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            MarinaEntities1 db      = new MarinaEntities1(); // create the DataAccess entity
            Customer        newCust = new Customer();        // empty Customer object
            bool            exists;                          // used for determining if user exists or not

            lblRegStatus.Text = "";
            if (txtFName.Text != "" && txtLName.Text != "" && txtCity.Text != "" &&
                txtPhone.Text != "" && txtEmail.Text != "" && txtPassword.Text != "")
            {
                try
                {// search the db for the email address
                    newCust = (from c in db.Customers
                               where c.EMail == txtEmail.Text
                               select c).Single();
                    exists = true; // yes we have an existing user
                }

                catch (System.InvalidOperationException)
                {                   // error when no data exists
                    exists = false; // no user found
                }

                if (!exists) // no user found, validate and create
                {
                    newCust.FirstName = txtFName.Text;
                    newCust.LastName  = txtLName.Text;
                    newCust.City      = txtCity.Text;
                    newCust.Phone     = txtPhone.Text;
                    newCust.EMail     = txtEmail.Text;
                    newCust.Salt      = newCust.GetSalt();
                    newCust.Password  = newCust.EncryptPassword(txtPassword.Text, newCust.Salt);
                    db.Customers.Add(newCust);
                    db.SaveChanges();
                    Session["Authenticated"] = true;
                    Session["Username"]      = txtEmail.Text;
                    Response.Redirect("LeaseSlip.aspx");
                }
            }
            else
            {
                lblRegStatus.Text = "All fields required";
            }
        }
示例#3
0
        public void GetLeases(string username)
        {
            MarinaEntities1 db = new MarinaEntities1(); // create DB object

            // use the username to get the customer from the database (mostly for their ID)
            cust = db.Customers.Where(c => c.EMail == username).Single();

            // get the slips that this customer has previously leased
            List <Slip> history = (from slip in db.Slips
                                   join l in db.Leases on slip.ID equals l.SlipID
                                   join c in db.Customers on l.CustomerID equals c.ID
                                   where l.CustomerID == cust.ID
                                   select slip).ToList();

            // put the list of this customer's leases in the DGV
            dgvLeases.DataSource = null;
            dgvLeases.DataSource = history;
            dgvLeases.DataBind();
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            MarinaEntities1 db = new MarinaEntities1(); // create DB object

            try
            {
                if (!(bool)Session["Authenticated"]) // if they somehow got here without authentication, kick them back
                {
                    Response.Redirect("Registration.aspx");
                }
            }
            catch (NullReferenceException)
            {
                Response.Redirect("Registration.aspx");
            }
            // get the username from the session data
            username = (string)Session["Username"];
            if (username != null && (bool)Session["Authenticated"] == true)
            {
                GetLeases(username);
            }
        }
示例#5
0
        public void DoLease(int slipNum)
        {
            //int chosenSlip = Convert.ToInt32(txtChosen.Text); // get the customer's choice of slip to lease


            using (MarinaEntities1 db = new MarinaEntities1())
            {
                // getting these again due to missing some crucial info in class while away -Tom
                List <int> leaseList = (from lease in db.Leases select lease.SlipID).ToList();
                List <int> availList = (from slip in db.Slips select slip.ID).ToList();


                // create a new lease with the customer and slip ID
                Lease leased = new Lease();
                leased.CustomerID = cust.ID;
                leased.SlipID     = slipNum;

                // save to the database
                db.Leases.Add(leased);
                db.SaveChanges();
                GetLeases(username);
                lvAvailableSlips.SelectedIndex = -1;
            }
        }