protected void btnLogin_Click(object sender, EventArgs e) { string studentNum = txtStudentNum.Text; string password = txtPassword.Text; using (BookStoreDBEntities entityContext = new BookStoreDBEntities()) { //Authenicate the user's credential againt data stored //in the Student table in the Registration DB by searching //for the student with the user entered studentNum and password Student students = (from student in entityContext.Students where student.StudentNum == studentNum && student.Password == password select student).FirstOrDefault <Student>(); if (students != null) { Session["studentNumber"] = txtStudentNum.Text; Response.Redirect("BookOrders.aspx"); } else { lblLoginError.Text = "Incorrect Student Number and/or Password!"; txtPassword.Text = ""; } } }
protected void Page_Load(object sender, EventArgs e) { //Redirect unauthenticated user to the Default page. if (Session["studentNumber"] == null) { Response.Redirect("Default.aspx"); } using (BookStoreDBEntities entityContext = new BookStoreDBEntities()) { //Get the ordered book list of the authenticated user. String studentNumber = Session["studentNumber"].ToString(); Student students = (from student in entityContext.Students where student.StudentNum == studentNumber select student).FirstOrDefault <Student>(); String id = Request.Params["id"]; String action = Request.Params["action"]; //If the user clicked the delete link of a book, //delete the selected book from the user's order if (!String.IsNullOrEmpty(id) && action == "Delete") { Book books1 = (from book in entityContext.Books where book.BookID == id select book).FirstOrDefault <Book>(); /*if (books != null) * { * entityContext.Books.Remove(books); * entityContext.SaveChanges(); * }*/ if (students != null && books1 != null) { students.Books.Remove(books1); entityContext.SaveChanges(); } } //If the user clicked a book's title, show the description of the book (use ShowBookDescrition method) if (!String.IsNullOrEmpty(id) && action == "ShowDescription") { Book books = (from book in entityContext.Books where book.BookID == id select book).FirstOrDefault <Book>(); if (books != null) { ShowBookDescription(books); } } //Display the book list of the user's order (use ShowBooks method) if (students != null) { ShowBooks(students.Books.ToList()); } } }