private void btnSave_Click(object sender, RoutedEventArgs e) { stu = db.Students.First(x => x.studentnumber == studentID); stu.firstname = this.txtFirst.Text.ToLower().Trim(); stu.middleinitial = this.txtMI.Text.ToLower().Trim(); stu.lastname = this.txtLast.Text.ToLower().Trim(); stu.email = this.txtEmail.Text.ToLower().Trim(); stu.phone = this.txtPhone.Text.ToLower().Trim(); stu.cardnumber = this.txtCard.Text.ToLower().Trim(); stu.pinnumber = this.txtPIN.Password.ToString(); bool problem = false; if (db.Students.Where(x => x.email == stu.email && x.studentnumber != studentID).Any()) { problem = true; } else if (!String.IsNullOrWhiteSpace(txtCard.Text)) { if (db.Students.Where(x => x.cardnumber == stu.cardnumber && x.studentnumber != studentID).Any()) { problem = true; } } if (problem) { UniversalError ue = new UniversalError("Error!", "Some of the information you've entered is already associated with another account."); ue.ShowDialog(); } else { db.SaveChanges(); SignIn si = new SignIn(); UniversalSuccess us = new UniversalSuccess("Yay!", "Your information has been saved."); us.ShowDialog(); this.Close(); si.Show(); } }
private void btnCheckOut_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrWhiteSpace(txtID.Text)) { txtID.Background = Brushes.LightPink; } else if (String.IsNullOrWhiteSpace(cmbEquipment.Text)) { cmbEquipment.Background = Brushes.LightPink; } else if (String.IsNullOrWhiteSpace(txtPin.Password.ToString())) { txtPin.Background = Brushes.LightPink; } else if (String.IsNullOrWhiteSpace(txtAdminPin.Password.ToString())) { txtAdminPin.Background = Brushes.LightPink; } else { Student stu = new Student(); bool isConfirmed = false; stu = db.Students.Where(x => x.studentnumber == txtID.Text || x.cardnumber == txtID.Text).First(); if (txtPin.Password.ToString() != stu.pinnumber) { UniversalError ue = new UniversalError("Error!", "This is not the correct pin number for " + stu.firstname + "'s account."); ue.ShowDialog(); txtPin.Background = Brushes.LightPink; } else { isConfirmed = db.Admins.Where(x => x.pin == txtAdminPin.Password.ToString()).Any(); if (!isConfirmed) { UniversalError ue = new UniversalError("Error!", "The Admin's password is incorrect."); ue.ShowDialog(); txtAdminPin.Background = Brushes.LightPink; } else { //Create a new loan here and add it to the database. Loan loan = new Loan(stu.studentnumber); loan.studentID = stu.studentnumber; loan.description = txtNote.Text; loan.tagnumber = txtTag.Text; loan.loandate = DateTime.Today.Date; loan.serialnumber = txtSerial.Text; loan.equipmenttype = cmbEquipment.Text; loan.active = true; db.Loans.Add(loan); db.SaveChanges(); SignIn pop = new SignIn(); UniversalSuccess us = new UniversalSuccess("Success!", "The item has been checked out."); us.ShowDialog(); this.Close(); pop.Show(); } } } }