protected void NoteSubmit_Click(object sender, EventArgs e) { using (WebhostEntities db = new WebhostEntities()) { Student student = db.Students.Find(SelectedStudentId); if (student.CourseRequestComments.Where(com => com.TermId == termId).Count() > 0) { CourseRequestComment comment = student.CourseRequestComments.Where(com => com.TermId == termId).ToList()[0]; comment.Notes = NotesEntry.Text; } else { CourseRequestComment comment = new CourseRequestComment() { id = db.CourseRequestComments.OrderBy(com => com.id).ToList().Last().id + 1, Notes = NotesEntry.Text, TermId = termId, StudentId = SelectedStudentId }; db.CourseRequestComments.Add(comment); } NotesStatus.Text = "Saved Notes!"; NotesStatus.CssClass = "success_highlight"; db.SaveChanges(); } }
protected void SubmitBtn_Click(object sender, EventArgs e) { using (WebhostEntities db = new WebhostEntities()) { int newCRN = db.CourseRequests.Count() > 0? db.CourseRequests.OrderBy(c => c.id).ToList().Last().id : -1; Student student = db.Students.Where(s => s.ID == SelectedStudentId).Single(); List <WebhostMySQLConnection.CourseRequest> coursereqs = student.CourseRequests.Where(cr => cr.TermId == termId).ToList(); foreach (WebhostMySQLConnection.CourseRequest cr in coursereqs) { if (cr.APRequests.Count > 0) { foreach (APRequest req in cr.APRequests) { req.Sections.Clear(); } db.APRequests.RemoveRange(cr.APRequests); cr.APRequests.Clear(); } } db.CourseRequests.RemoveRange(coursereqs); if (SeniorProjectCB.Checked) { WebhostMySQLConnection.CourseRequest sp = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = 1995, IsSecondary = false, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(sp); } if (LSP.Checked) { WebhostMySQLConnection.CourseRequest sp = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = 2057, IsSecondary = false, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(sp); } if (ESL.Checked) { WebhostMySQLConnection.CourseRequest sp = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = student.GraduationYear > 2018 ? 2058 : 2059, IsSecondary = false, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(sp); } // Ignore if already enrolled in English Full Year class. if (!EnglishFullYearCB.Checked) { WebhostMySQLConnection.CourseRequest eng1 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(English1DDL.SelectedValue), IsSecondary = false, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(eng1); if (English2DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest eng2 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(English2DDL.SelectedValue), IsSecondary = EnglishSelectionPriority.SelectedIndex == 0, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(eng2); } } if (!HistoryFullYearCB.Checked) { if (History1DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest hist1 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(History1DDL.SelectedValue), IsSecondary = false, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(hist1); if (History2DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest hist2 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(History2DDL.SelectedValue), IsSecondary = HistorySelectionPriority.SelectedIndex == 0, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(hist2); } } } if (!MathFullYear.Checked) { if (Math1DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest math1 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(Math1DDL.SelectedValue), IsSecondary = false, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(math1); if (Math2DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest math2 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(Math2DDL.SelectedValue), IsSecondary = MathPriority.SelectedIndex == 0, IsGlobalAlternate = MathPriority.SelectedIndex == 2, TermId = termId }; db.CourseRequests.Add(math2); } } } if (!WorldLanguageSkip.Checked) { if (WorldLang1DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest wl1 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(WorldLang1DDL.SelectedValue), IsSecondary = false, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(wl1); if (WorldLang2DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest wl2 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(WorldLang2DDL.SelectedValue), IsSecondary = MathPriority.SelectedIndex == 0, IsGlobalAlternate = MathPriority.SelectedIndex == 2, TermId = termId }; db.CourseRequests.Add(wl2); } } } if (Tech1DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest tech1 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(Tech1DDL.SelectedValue), IsSecondary = false, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(tech1); if (Tech2DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest tech2 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(Tech2DDL.SelectedValue), IsSecondary = TechPriority.SelectedIndex == 0, IsGlobalAlternate = TechPriority.SelectedIndex == 2, TermId = termId }; db.CourseRequests.Add(tech2); } } if (!ScienceFullYearCB.Checked) { if (Science1DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest sci1 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(Science1DDL.SelectedValue), IsSecondary = false, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(sci1); if (Science2DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest sci2 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(Science2DDL.SelectedValue), IsSecondary = SciencePriority.SelectedIndex == 0, IsGlobalAlternate = SciencePriority.SelectedIndex == 2, TermId = termId }; db.CourseRequests.Add(sci2); } if (Science3DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest sci3 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(Science3DDL.SelectedValue), IsSecondary = true, IsGlobalAlternate = true, TermId = termId }; db.CourseRequests.Add(sci3); } } } if (Art1DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest art1 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(Art1DDL.SelectedValue), IsSecondary = false, IsGlobalAlternate = false, TermId = termId }; db.CourseRequests.Add(art1); if (Art2DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest art2 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(Art2DDL.SelectedValue), IsSecondary = ArtPriority.SelectedIndex == 0, IsGlobalAlternate = ArtPriority.SelectedIndex == 2, TermId = termId }; db.CourseRequests.Add(art2); } if (Art3DDL.SelectedIndex >= 0) { WebhostMySQLConnection.CourseRequest art2 = new WebhostMySQLConnection.CourseRequest() { id = ++newCRN, StudentId = SelectedStudentId, CourseId = Convert.ToInt32(Art3DDL.SelectedValue), IsSecondary = Art3Priority.SelectedIndex == 1, IsGlobalAlternate = Art3Priority.SelectedIndex == 0, TermId = termId }; db.CourseRequests.Add(art2); } } if (student.CourseRequestComments.Where(crn => crn.TermId == termId).Count() > 0) { CourseRequestComment crn = student.CourseRequestComments.Where(c => c.TermId == termId).Single(); crn.Notes = NotesInput.Text; } else { int crnid = db.CourseRequestComments.Count() > 0?db.CourseRequestComments.OrderBy(c => c.id).ToList().Last().id + 1:0; CourseRequestComment crn = new CourseRequestComment() { id = crnid, Notes = NotesInput.Text, StudentId = SelectedStudentId, TermId = termId }; db.CourseRequestComments.Add(crn); } db.SaveChanges(); Response.Redirect("~/CourseRequestConfirmed.aspx"); } }
protected void LoadRequests() { if (SelectedStudentId == -1) { SignUpPanel.Visible = false; return; } SignUpPanel.Visible = true; using (WebhostEntities db = new WebhostEntities()) { Student student = db.Students.Where(s => s.ID == SelectedStudentId).Single(); bool cleanedUp = false; List <int> reqCourseIds = new List <int>(); // Clean up bad requests... foreach (WebhostMySQLConnection.CourseRequest cr in student.CourseRequests.Where(c => c.TermId == termId).ToList()) { if (reqCourseIds.Contains(cr.CourseId)) { cleanedUp = true; LogWarning("Deleting Duplicate Course Request for {0} {1} - {2}.", student.FirstName, student.LastName, cr.RequestableCourse.Course.Name); db.CourseRequests.Remove(cr); } else { reqCourseIds.Add(cr.CourseId); } } if (cleanedUp) { db.SaveChanges(); } List <int> requests = student.CourseRequests.Where(cr => cr.TermId == termId).Select(cr => cr.id).ToList(); foreach (int reqId in requests) { RequestCourseSelector selector = (RequestCourseSelector)LoadControl("~/UserControls/RequestCourseSelector.ascx"); selector.Initialize(); selector.CourseRequestId = reqId; TableRow row = new TableRow(); TableCell cell = new TableCell(); cell.Controls.Add(selector); row.Cells.Add(cell); SavedRequestsTable.Rows.Add(row); } if (student.CourseRequestComments.Where(com => com.TermId == termId).Count() > 0) { CourseRequestComment comment = student.CourseRequestComments.Where(com => com.TermId == termId).ToList()[0]; NotesEntry.Text = comment.Notes; NotesStatus.Text = "Notes have been saved."; NotesStatus.CssClass = "success_highlight"; } else { NotesStatus.Text = "No Notes have been saved."; NotesStatus.CssClass = ""; } } }