protected void btnAddCrsInfo(object sender, EventArgs e) { if (Page.IsValid) { using (var entityContext = new StudentRecordEntities()) { List <Course> courses = entityContext.Courses.ToList <Course>(); /* bool valid = true; * foreach(Course cr in courses) * { * * if(cr.Code == courseNum.Text) * { * lblErrNum.Text = "Course with this code already exist"; * valid = false; * break; * } * } * if (valid) * { */ Course course = new Course(); course.Code = courseNum.Text; course.Title = courseName.Text; entityContext.Courses.Add(course); entityContext.SaveChanges(); DisplayCourses(); } } }
protected void btnAddStudent_OnClick(object sender, EventArgs e) { using (var studentRecords = new StudentRecordEntities()) { Course course = (from a in studentRecords.Courses where a.Code == courseList.SelectedValue select a).FirstOrDefault(); List <AcademicRecord> records = (from b in course.AcademicRecords where b.StudentId == number.Text select b).ToList(); if (records.Count > 0) { numberError.Text = "The system already has record of this student for the selected course"; ShowStudent(course); } else { Student student = (from c in studentRecords.Students where c.Id == number.Text select c).FirstOrDefault(); if (student == null) { student = new Student(); student.Id = number.Text; student.Name = name.Text; studentRecords.Students.Add(student); } AcademicRecord academic = new AcademicRecord(); academic.CourseCode = course.Code; academic.Grade = int.Parse(grade.Text); academic.Student = student; course.AcademicRecords.Add(academic); studentRecords.SaveChanges(); Response.Redirect("AddStudent.aspx"); } } }
protected void btnNewCourse_Click(object sender, EventArgs e) { //coursecode that was input converted and trimmed string courseCode = txtCourseNumber.Text.ToUpper().Trim(); //Entity frameword to add a new course to database using (StudentRecordEntities entityContext = new StudentRecordEntities()) { //checking if course code is already in database if ((from c in entityContext.Courses where c.Code == courseCode select c).FirstOrDefault() != null) { txtCourseNumberExist.Text = "Course with this code already exists"; } else { //creating new course and adding it to database (taking courseNumber that's already input and adding new Name) Course course = new Course(); course.Code = courseCode; course.Title = txtCourseName.Text; entityContext.Courses.Add(course); entityContext.SaveChanges(); //this is important... Response.Redirect("AddCourse.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { lblErrNum.Text = ""; LinkButton btnHome = (LinkButton)Master.FindControl("btnHome"); btnHome.Click += (o, a) => Response.Redirect("Default.aspx"); BulletedList menulist = (BulletedList)Master.FindControl("topMenu"); if (!IsPostBack) { menulist.Items.Add(new ListItem("Add Course")); menulist.Items.Add(new ListItem("Add Student Records")); } menulist.Click += (o, a) => { if (a.Index == 1) { Response.Redirect("AddStudent.aspx"); } }; using (var entityContext = new StudentRecordEntities()) { var courses = (from course in entityContext.Courses orderby course.Code select course).ToList(); } DisplayCourses(); }
protected void Page_PreRender(object sender, EventArgs e) { using (StudentRecordEntities entityContext = new StudentRecordEntities()) { string selectedCourseCode = Session["selectedCourseCode"] as string; //////////////////////////////////////////////////////////////////////////////////////// //useless? List <AcademicRecord> records = entityContext.AcademicRecords.ToList <AcademicRecord>(); string action = Request.Params["action"] as string; if (action == "delete") { string ID = Request.Params["id"]; var student = (from s in entityContext.Students where s.Id == ID select s).FirstOrDefault <Student>(); if (student != null) { for (int i = student.AcademicRecords.Count() - 1; i >= 0; i--) { var ar = student.AcademicRecords.ElementAt <AcademicRecord>(i); student.AcademicRecords.Remove(ar); } } entityContext.Students.Remove(student); entityContext.SaveChanges(); Response.Redirect("AddStudent.aspx"); } else if (action == "change") { string idFromTable = Request.Params["id"]; var matchingStudent = (from s in entityContext.Students where s.Id == idFromTable select s).FirstOrDefault <Student>(); if (matchingStudent != null) { drpCourse.Text = selectedCourseCode; drpCourse.Enabled = false; txtStudentID.Text = idFromTable; txtStudentID.ReadOnly = true; txtStudentName.Text = matchingStudent.Name; txtStudentName.ReadOnly = true; txtGrade.Text = ""; } } List <AcademicRecord> DisplayRecordList = (from ar in entityContext.AcademicRecords where ar.CourseCode == selectedCourseCode select ar).ToList <AcademicRecord>(); string selectedCourse = Session["selectedCourseCode"] as string; drpCourse.Text = selectedCourse; ShowAcademicRecords(DisplayRecordList, Request.Params["sort"]); } }
protected void Page_Load(object sender, EventArgs e) { LinkButton btnHome = (LinkButton)Master.FindControl("btnHome"); btnHome.Click += (s, a) => Response.Redirect("Default.aspx"); BulletedList topMenu = (BulletedList)Master.FindControl("topMenu"); if (!IsPostBack) { topMenu.Items.Add(new ListItem("Add Courses")); } topMenu.Click += (s, a) => Response.Redirect("AddCourse.aspx"); if (!IsPostBack) { using (StudentRecordEntities entityContext = new StudentRecordEntities()) { List <Course> courses = entityContext.Courses.ToList <Course>(); foreach (Course course in courses) { ListItem item = new ListItem(course.Code + "-" + course.Title, course.Code); DropDownListCourses.Items.Add(item); } } } }
protected void Page_Load(object sender, EventArgs e) { LinkButton btnHome = (LinkButton)Master.FindControl("btnHome"); btnHome.Click += (s, a) => Response.Redirect("Default.aspx"); BulletedList topMenu = (BulletedList)Master.FindControl("topMenu"); topMenu.Click += (s, a) => Response.Redirect("AddCourse.aspx"); if (!IsPostBack) { topMenu.Items.Add(new ListItem("Add Course")); } if (!IsPostBack) { using (var studentRecords = new StudentRecordEntities()) { var cs = (from c in studentRecords.Courses orderby c.Title select new { CourseId = c.Code, CourseText = c.Code + "-" + c.Title }).ToList(); if (cs.Count == 0) { Response.Redirect("AddCourse.aspx"); } else { courseList.DataSource = cs; courseList.DataTextField = "CourseText"; courseList.DataValueField = "CourseId"; courseList.DataBind(); } } } }
private void DisplayStdn() { while (tblStudentInfo.Rows.Count > 1) { tblStudentInfo.Rows.RemoveAt(1); } using (var entityContext = new StudentRecordEntities()) { var academRecords = (from academRecord in entityContext.AcademicRecords orderby academRecord.Student.Id select academRecord).ToList(); bool isExist = false; if (drpCourseSelection.SelectedIndex != 0) { foreach (AcademicRecord academRecord in academRecords) { var a = academRecord.Course.Title; var b = Session["selectedcourseName"].ToString(); if (academRecord.Course.Title.Trim() != Session["selectedcourseName"].ToString()) { continue; } else { isExist = true; Student student = academRecord.Student; TableRow row = new TableRow(); TableCell cell = new TableCell(); cell.Text = student.Id; row.Cells.Add(cell); cell = new TableCell(); cell.Text = academRecord.Student.Name; row.Cells.Add(cell); cell = new TableCell(); cell.Text = academRecord.Grade + ""; row.Cells.Add(cell); tblStudentInfo.Rows.Add(row); } } } if (!isExist) { TableRow lastRow = new TableRow(); TableCell lastRowCell = new TableCell(); lastRowCell.Text = "No Courses record exist"; lastRowCell.ForeColor = System.Drawing.Color.Red; lastRowCell.ColumnSpan = 3; lastRowCell.HorizontalAlign = HorizontalAlign.Center; lastRow.Cells.Add(lastRowCell); tblStudentInfo.Rows.Add(lastRow); } } }
protected void courseList_SelectedIndexChanged(object sender, EventArgs e) { using (var studentRecords = new StudentRecordEntities()) { Course course = (from a in studentRecords.Courses where a.Code == courseList.SelectedValue select a).FirstOrDefault(); ShowStudent(course); } }
protected void ShowCourseTable(List <Course> test, string sort = "code") { using (var context = new StudentRecordEntities()) { List <Course> courses = context.Courses.ToList(); for (int i = Table.Rows.Count - 1; i > 0; i--) { Table.Rows.RemoveAt(i); } if (courses == null || courses.Count == 0) { TableRow errorRow = new TableRow(); TableCell errorCell = new TableCell(); errorCell.Text = "No cources in system yet"; errorCell.ForeColor = System.Drawing.Color.Red; errorCell.ColumnSpan = 4; errorCell.HorizontalAlign = HorizontalAlign.Center; errorRow.Cells.Add(errorCell); Table.Rows.Add(errorRow); } else { if (sort == "code") { courses.Sort((c1, c2) => c1.Code.CompareTo(c2.Code)); } else if (sort == "title") { courses.Sort((c1, c2) => c1.Title.CompareTo(c2.Title)); } if (Session["order"] != null && (string)Session["order"] == "decending") { courses.Reverse(); Session["order"] = "ascending"; } else { Session["order"] = "descending"; } foreach (var course in courses) { TableRow row = new TableRow(); TableCell cell = new TableCell(); cell.Text = course.Code; row.Cells.Add(cell); cell = new TableCell(); cell.Text = course.Title; row.Cells.Add(cell); Table.Rows.Add(row); } } } }
protected void submitBtn_Click(object sender, EventArgs e) { //validate checklist if (checkBox.SelectedItem == null) //if nothing is selected { validateCheckList.InnerText = "You must choose at least one role for this employee"; } else //if at least one checkbox is selected, continue code { validateCheckList.InnerText = ""; using (StudentRecordEntities entityContext = new StudentRecordEntities()) { //check if emplyee exists var employee = (from em in entityContext.Employees where em.UserName == userNameTxt.Text select em).FirstOrDefault <Employee>(); if (employee != null) //if user name already exists { spanUserName.InnerText = "This user name already exists!"; } else //if username doesn't exist, go on with code { spanUserName.InnerText = ""; //creating employee Employee newEmployee = new Employee(); newEmployee.Name = nameTxt.Text; newEmployee.UserName = userNameTxt.Text; newEmployee.Password = passwordTxt.Text; //getting list of roles selected for the employee Role role = null; foreach (ListItem item in checkBox.Items) { if (item.Selected == true) { int selectedRoleId = int.Parse(item.Value); //looking through role table, comparing role.id with the id of each selected item on chekbox, assingned on foreach loop role = (from r in entityContext.Roles where r.Id == selectedRoleId select r).FirstOrDefault <Role>(); newEmployee.Roles.Add(role); //for every matching item, add respective role to newEmployee } } entityContext.Employees.Add(newEmployee); entityContext.SaveChanges(); Response.Redirect("AddEmployee.aspx"); } } } }
protected void Page_PreRender(object sender, EventArgs e) { //Entity Framework using (StudentRecordEntities entityContext = new StudentRecordEntities()) { List <Employee> employees = entityContext.Employees.ToList <Employee>(); //List<Role> roles = entityContext.Roles.ToList<Role>(); ShowEmployeeInfo(employees); } }
private void DisplayCourses() { while (tblCourseInfo.Rows.Count > 1) { tblCourseInfo.Rows.RemoveAt(1); } using (var entityContext = new StudentRecordEntities()) { List <Course> courses = entityContext.Courses.ToList <Course>(); string sort = Request.Params["sort"]; if (sort == "code") { if (Session["order"] == null || Session["order"].ToString() == "asc") { courses.Sort((x, y) => string.Compare(x.Code, y.Code)); Session["order"] = "desc"; } else { courses.Sort((x, y) => string.Compare(y.Code, x.Code)); Session["order"] = "asc"; } } if (sort == "title") { if (Session["order"] == null || Session["order"].ToString() == "asc") { courses.Sort((x, y) => string.Compare(x.Title, y.Title)); Session["order"] = "desc"; } else { courses.Sort((x, y) => string.Compare(y.Title, x.Title)); Session["order"] = "asc"; } } foreach (Course course in courses) { TableRow row = new TableRow(); TableCell cell = new TableCell(); cell.Text = course.Code; row.Cells.Add(cell); cell = new TableCell(); cell.Text = course.Title; row.Cells.Add(cell); tblCourseInfo.Rows.Add(row); } } }
protected void Page_PreRender(object sender, EventArgs e) { //Entity Framework using (StudentRecordEntities entityContext = new StudentRecordEntities()) { //creates a list of courses from Student Records enetities List <Course> courses = entityContext.Courses.ToList <Course>(); //gets string from action string action = Request.Params["action"] as string; if (action == "delete") { //determines which course via params string codeFromTable = Request.Params["id"]; //if course code matches course in database select it var matchingCourse = (from c in entityContext.Courses where c.Code == codeFromTable select c).FirstOrDefault <Course>(); //if course isn't null, remove it from Academic record if (matchingCourse != null) { for (int i = matchingCourse.AcademicRecords.Count() - 1; i >= 0; i--) { var matchingAcademicRecord = matchingCourse.AcademicRecords.ElementAt <AcademicRecord>(i); matchingCourse.AcademicRecords.Remove(matchingAcademicRecord); } } //remove from database entityContext.Courses.Remove(matchingCourse); entityContext.SaveChanges(); Response.Redirect("AddCourse.aspx"); } else if (action == "edit") { string codeFromTable = Request.Params["id"]; var matchingCourse = (from c in entityContext.Courses where c.Code == codeFromTable select c).FirstOrDefault <Course>(); if (matchingCourse != null) { txtCourseName.Text = matchingCourse.Title; txtCourseNumber.Text = codeFromTable; txtCourseNumber.ReadOnly = true; } } ShowCourseInfo(courses, Request.Params["sort"]); } }
protected void ExistanceValidator(object sender, ServerValidateEventArgs args) { using (var entityContext = new StudentRecordEntities()) { List <Course> courses = entityContext.Courses.ToList <Course>(); foreach (Course cr in courses) { if (cr.Code == courseNum.Text) { args.IsValid = false; break; } } } }
protected void DropDownListCourses_SelectedIndexChanged(object sender, EventArgs e) { if (DropDownListCourses.SelectedValue != "-1") { string selectedCourseID = DropDownListCourses.SelectedValue; using (StudentRecordEntities entityContext = new StudentRecordEntities()) { var studentsInSelectedCourse = (from a in entityContext.AcademicRecords where a.CourseCode == selectedCourseID select a).ToList <AcademicRecord>(); showCourseInfo(studentsInSelectedCourse); } } }
protected void btnAddNewStudent_Click(object sender, EventArgs e) { string selectedCourseCode = Session["selectedCourseCode"] as string; if (selectedCourseCode != null && selectedCourseCode != "-1") { using (StudentRecordEntities entityContext = new StudentRecordEntities()) { Course selectedCourse = (from c in entityContext.Courses where c.Code == selectedCourseCode select c).FirstOrDefault <Course>(); //might need .ToList() or list type after FirstorDefault string idInput = txtStudentID.Text.Trim().ToUpper(); Student newStudent = (from s in entityContext.Students where s.Id == idInput select s).FirstOrDefault <Student>(); if (newStudent == null) { newStudent = new Student(); newStudent.Name = txtStudentName.Text; newStudent.Id = txtStudentID.Text; entityContext.Students.Add(newStudent); AcademicRecord newRecord = new AcademicRecord(); newRecord.Student = newStudent; newRecord.Course = selectedCourse; newRecord.Grade = int.Parse(txtGrade.Text); entityContext.AcademicRecords.Add(newRecord); entityContext.SaveChanges(); Response.Redirect("AddStudent.aspx"); } else { AcademicRecord ar = (from a in entityContext.AcademicRecords where a.Course.Code == selectedCourse.Code && a.StudentId == newStudent.Id select a).FirstOrDefault <AcademicRecord>(); //check if the system already has a record of this student/ course? if (ar != null) { txtStudentIdExists.Text = "The system already has record of this student in this class"; } } } } }
protected void ExistanceValidator(object sender, ServerValidateEventArgs args) { using (var entityContext = new StudentRecordEntities()) { string courseID = Session["selectedcourseCode"].ToString(); List <AcademicRecord> StidCheck = (from academRecord in entityContext.AcademicRecords where academRecord.StudentId == stdId.Text && academRecord.CourseCode == courseID select academRecord ).ToList(); if (StidCheck.Count != 0) { args.IsValid = false; } } }
protected override void Page_Load(object sender, EventArgs e) { base.Page_Load(sender, e); //loading base page LinkButton btnHome = (LinkButton)Master.FindControl("btnHome"); //loading button home from base page //displaying employees list using (StudentRecordEntities entityContext = new StudentRecordEntities()) { List <Employee> empList = entityContext.Employees.ToList <Employee>(); List <Role> roleList = entityContext.Roles.ToList <Role>(); //displaying checkbox, populating from the database if (!IsPostBack) { foreach (Role role in entityContext.Roles.ToList <Role>()) { checkBox.Items.Add(new ListItem(role.Role1, role.Id.ToString())); //using name as text(Role1) + role id coming from db as "index" (1, 2, 3) } } //displaying table content foreach (Employee em in empList) //going through each employee { TableRow row = new TableRow(); TableCell cell = new TableCell(); cell.Text = em.Name.ToString(); row.Cells.Add(cell); cell = new TableCell(); cell.Text = em.UserName.ToString(); row.Cells.Add(cell); cell = new TableCell(); string stRole = ""; foreach (Role l in em.Roles) //looping through each role of the employee { stRole = stRole + "," + l.Role1.ToString(); //adding each role name (Role1) to stRole variable } stRole = stRole.TrimStart(','); cell.Text = stRole; row.Cells.Add(cell); tableSort.Rows.Add(row); } } }
protected void btnChangeCourseInfo_Click(object sender, EventArgs e) { string courseCode = txtCourseNumber.Text.ToUpper().Trim(); using (StudentRecordEntities entityContext = new StudentRecordEntities()) { Course course = (from c in entityContext.Courses where c.Code == courseCode select c).FirstOrDefault <Course>(); if (course != null) { course.Title = txtCourseName.Text; entityContext.Entry(course).State = System.Data.Entity.EntityState.Modified;; entityContext.SaveChanges(); Response.Redirect("AddCourse.aspx"); } } }
protected void btnChangeGrade_Click(object sender, EventArgs e) { string studentID = txtStudentID.Text.ToUpper().Trim(); using (StudentRecordEntities entityContext = new StudentRecordEntities()) { string selectedCourseCode = Session["selectedCourseCode"] as string; var academicRecord = (from ar in entityContext.AcademicRecords where ar.CourseCode == selectedCourseCode && ar.StudentId == txtStudentID.Text select ar).FirstOrDefault <AcademicRecord>(); academicRecord.Grade = int.Parse(txtGrade.Text); entityContext.Entry(academicRecord).State = System.Data.Entity.EntityState.Modified;; entityContext.SaveChanges(); Response.Redirect("AddStudent.aspx"); } }
protected void btnAdd_Click(object sender, EventArgs e) { using (var entityContext = new StudentRecordEntities()) { if (Page.IsValid) { List <Student> students = entityContext.Students.ToList <Student>(); List <AcademicRecord> academRecords = entityContext.AcademicRecords.ToList <AcademicRecord>(); bool stExist = false; foreach (Student student in students) { if (student.Id == stdId.Text) { AcademicRecord academRecord = new AcademicRecord(); academRecord.CourseCode = Session["selectedcourseCode"].ToString(); academRecord.Student = student; academRecord.Grade = Int32.Parse(stdGrade.Text); entityContext.AcademicRecords.Add(academRecord); entityContext.SaveChanges(); stExist = true; break; } } if (!stExist) { Student std = new Student(); std.Id = stdId.Text; std.Name = stdName.Text; entityContext.Students.Add(std); AcademicRecord academRecord = new AcademicRecord(); academRecord.CourseCode = Session["selectedcourseCode"].ToString(); academRecord.Student = std; academRecord.Grade = Int32.Parse(stdGrade.Text); entityContext.AcademicRecords.Add(academRecord); entityContext.SaveChanges(); } } } DisplayStdn(); }
protected void btnSubmit_Click(object sender, EventArgs e) { Course course = new Course(); course.Code = courseNumber.Text; course.Title = courseName.Text; using (var courseRecord = new StudentRecordEntities()) { if (courseRecord.Courses.Where(c => c.Code == courseNumber.Text).Count() > 0) { lblError.Text = "Course with this code already exists"; return; } else { courseRecord.Courses.Add(course); courseRecord.SaveChanges(); Response.Redirect("AddCourse.aspx"); } } }
protected void btnLogin_Click(object sender, EventArgs e) { string useName = txtUserName.Text.ToLower().Trim(); string psd = txtPassword.Text.Trim(); using (StudentRecordEntities entityContext = new StudentRecordEntities()) { //check if user is in database: Employee em = (from emp in entityContext.Employees where emp.UserName == useName && emp.Password == psd select emp).FirstOrDefault <Employee>(); if (em != null) //if system finds something - user is authenticated { FormsAuthentication.RedirectFromLoginPage(em.Id.ToString(), false); //authenticating user Session["aut"] = 1; //creating session to indicate authentication } else //user not in database { lblLoginError.Text = "The entered username and/or password are incorrect!"; } } }
protected void ButtonSubmitCourseInformation_Click(object sender, EventArgs e) { string courseNumber = TextBoxCourseNumber.Text; string courseName = TextBoxCourseName.Text; using (StudentRecordEntities entityContext = new StudentRecordEntities()) { Course course = new Course(); course.Code = courseNumber; course.Title = courseName; var cours = (from c in entityContext.Courses where c.Code == courseNumber select c).FirstOrDefault <Course>(); if (cours != null) { LabelErrorMessage.Text = "Course with this code already exist"; } else { entityContext.Courses.Add(course); entityContext.SaveChanges(); LabelErrorMessage.Text = ""; } } using (StudentRecordEntities entityContext = new StudentRecordEntities()) { List <Course> courses = entityContext.Courses.ToList <Course>(); showCourseInfo(courses); } }
protected void Page_Load(object sender, EventArgs e) { LinkButton btnHome = (LinkButton)Master.FindControl("btnHome"); btnHome.Click += (o, a) => Response.Redirect("Default.aspx"); BulletedList menulist = (BulletedList)Master.FindControl("topMenu"); if (!IsPostBack) { menulist.Items.Add(new ListItem("Add Course")); menulist.Items.Add(new ListItem("Add Student Records")); } menulist.Click += (o, a) => { if (a.Index == 0) { Response.Redirect("AddCourse.aspx"); } }; using (var entityContext = new StudentRecordEntities()) { var courses = (from course in entityContext.Courses orderby course.Code select course).ToList(); if (!IsPostBack) { foreach (Course course in courses) { ListItem item = new ListItem(course.Code + " - " + course.Title); drpCourseSelection.Items.Add(item); Session["selectedcourseName"] = ""; Session["selectedcourseCode"] = ""; } DisplayStdn(); } } }
protected void Page_Load(object sender, EventArgs e) { LinkButton btnHome = (LinkButton)Master.FindControl("btnHome"); btnHome.Click += (s, a) => Response.Redirect("Default.aspx"); BulletedList topMenu = (BulletedList)Master.FindControl("topMenu"); if (!IsPostBack) { topMenu.Items.Add(new ListItem("Add Student Records")); } topMenu.Click += (s, a) => Response.Redirect("AddStudent.aspx"); using (StudentRecordEntities entityContext = new StudentRecordEntities()) { List <Course> courses = entityContext.Courses.ToList <Course>(); showCourseInfo(courses); } }
protected void btnLogin_Click(object sender, EventArgs e) { string userName = txtUserName.Text.ToLower().Trim(); string password = txtPassword.Text.Trim(); //taken from slides //slides were login.aspx.cs, not default. webconfig automatically redirects to default.aspx using (StudentRecordEntities entityContext = new StudentRecordEntities()) { Employee em = (from emp in entityContext.Employees where emp.UserName == userName && emp.Password == password select emp).FirstOrDefault <Employee>(); if (em != null) { FormsAuthentication.RedirectFromLoginPage(em.Id.ToString(), false); } else { lblLoginError.Text = "The enetered username and/ or password are incorrect!"; } } }
protected void btnAddEmployee_Click(object sender, EventArgs e) { string employeeName = txtFullName.Text.ToUpper().Trim(); string employeeUsername = txtUsername.Text.ToLower().Trim(); string employeePassword = txtPassword.Text.Trim(); //Entity framework to add a new employee to database using (StudentRecordEntities entityContext = new StudentRecordEntities()) { //checking if employee is already in database if ((from em in entityContext.Employees where em.Name == employeeName || em.UserName == employeeUsername select em).FirstOrDefault() != null) { lblEmployeeError.Text = "Employee with this name or username already exists"; } else { //creating new employee and adding it to database (taking username that's already input and adding new Name) //make counter for employee ID List <Employee> employeesList = entityContext.Employees.ToList <Employee>(); List <string> selectedRoles = checkboxListRoles.Items.Cast <ListItem>() .Where(li => li.Selected) .Select(li => li.Value) .ToList(); Employee newEmployee = new Employee(); //The following code was written by Eric Taylor//////////// var Department_Chair = (from dc in entityContext.Roles where dc.Role1 == "Department Chair" select dc).FirstOrDefault <Role>(); var Coordinator = (from c in entityContext.Roles where c.Role1 == "Coordinator" select c).FirstOrDefault <Role>(); var Instructor = (from i in entityContext.Roles where i.Role1 == "Instructor" select i).FirstOrDefault <Role>(); for (int i = 0; i < selectedRoles.Count; i++) { if (selectedRoles[i].Contains("Department Chair")) { newEmployee.Roles.Add(Department_Chair); } else if (selectedRoles[i].Contains("Coordinator")) { newEmployee.Roles.Add(Coordinator); } else if (selectedRoles[i].Contains("Instructor")) { newEmployee.Roles.Add(Instructor); } } ///////////////////////////////////////////////////////// newEmployee.Name = txtFullName.Text; newEmployee.UserName = txtUsername.Text; newEmployee.Password = txtPassword.Text; entityContext.Employees.Add(newEmployee); entityContext.SaveChanges(); Response.Redirect("AddEmployee.aspx"); } } }
protected override void Page_Load(object sender, EventArgs e) { #region set top menu base.Page_Load(sender, e); BulletedList topMenu = (BulletedList)Master.FindControl("topMenu"); topMenu.Items[1].Enabled = false; #endregion int selectedIndex = drpCourse.SelectedIndex; if (!IsPostBack) { //when the page loads: using the database of student records make a list of courses //order them by title and apply value and text based on paramaters //write them to a list using (StudentRecordEntities entityContext = new StudentRecordEntities()) { var courseList = (from c in entityContext.Courses orderby c.Title select new { Value = c.Code, Text = (c.Code + " - " + c.Title) }).ToList(); //if there are no courses in the list reload addStudent? if (courseList.Count == 0) { Response.Redirect("AddCourse.aspx"); } //add the databound items to the dropdown menu drpCourse.AppendDataBoundItems = true; drpCourse.DataTextField = "Text"; drpCourse.DataValueField = "Value"; drpCourse.DataSource = courseList; //does session go here? drpCourse.SelectedValue = Session["selectedCourseCode"] as string; //databinding what? drpCourse.DataBind(); drpCourse.Enabled = true; //does this go here? drpCourse.SelectedIndex = selectedIndex; txtStudentName.Text = ""; txtStudentName.ReadOnly = false; txtGrade.Text = ""; } } string action = Request.Params["action"] as string; if (action == "change") { btnSaveStudent.Click -= btnAddNewStudent_Click; btnSaveStudent.Click += btnChangeGrade_Click; } else { btnSaveStudent.Click += btnAddNewStudent_Click; btnSaveStudent.Click -= btnChangeGrade_Click; } txtStudentIdExists.Text = ""; }