private void button1_Click(object sender, EventArgs e) { if (validationProvider1.IsValid) { Course cr = new Course(); cr.CourseName = courseNameTextBox.Text; cr.TimeSlot = timeSlotTextBox.Text; cr.DaysOfWeek = DOWTextBox.Text; if (comboBox1.SelectedIndex == 0) { cr.ProfID = null; } else { cr.ProfID = ((Profs)allprofs[comboBox1.SelectedIndex]).ProfID; } errorLabel.Visible = false; if (EditingType == 0) { cr.AddCourse(); } else { cr.UpdateCourse(CID); } Close(); } else { errorLabel.Text = "There are some errors"; errorLabel.Visible = true; } }
public void ContentChanging() { var id = new Guid(); var cons = new Course("test-course", id); var test = new Course("test-course", id); var course = new CourseInformation("test-room", DateTime.Now, TimeSpan.Zero, "test-teacher", id); var exam = new ExamInformation("test-room", DateTime.Now, TimeSpan.Zero, id); Assert.AreEqual(cons, test); Assert.IsFalse(test.Contains(course)); Assert.IsFalse(test.Contains(exam)); Assert.IsTrue(test.AddCourse(course)); Assert.IsFalse(test.AddCourse(course)); Assert.IsTrue(test.Contains(course)); Assert.IsFalse(test.Contains(exam)); Assert.IsTrue(test.AddExam(exam)); Assert.IsFalse(test.AddExam(exam)); Assert.IsTrue(test.Contains(course)); Assert.IsTrue(test.Contains(exam)); Assert.AreNotEqual(cons, test); Assert.IsTrue(test.DeleteCourse(course)); Assert.IsFalse(test.DeleteCourse(course)); Assert.IsTrue(test.DeleteExam(exam)); Assert.IsFalse(test.DeleteExam(exam)); Assert.AreEqual(cons, test); Assert.IsFalse(test.Contains(course)); Assert.IsFalse(test.Contains(exam)); Assert.IsTrue(test.AddCourse(course)); Assert.IsTrue(test.AddExam(exam)); Assert.IsTrue(test.Contains(course)); Assert.IsTrue(test.Contains(exam)); }
public ActionResult EditCourse(Course tmpCourse) { // Make sure no two handicaps are the same HashSet <int> hcSet = new HashSet <int>(); foreach (Hole h in tmpCourse.HoleList) { if (!h.Handicap.HasValue) { continue; } if (hcSet.Contains((int)h.Handicap)) { ModelState.AddModelError(String.Empty, "Duplicate hole handicaps detected."); return(View("EditCourse", tmpCourse)); } else { hcSet.Add((int)h.Handicap); } } // Make sure that if any handicaps are entered that all holes // with a Par value entered have a handicap entered. if (tmpCourse.HoleList.Exists(x => x.Handicap.HasValue)) { foreach (Hole h in tmpCourse.HoleList.Where(x => x.Par != 0)) { if (!h.Handicap.HasValue) { ModelState.AddModelError(String.Empty, "Not all holes have a handicap specified."); return(View("EditCourse", tmpCourse)); } } } try { if (tmpCourse.CourseID == 0) { Course.AddCourse(tmpCourse); } else { Course.UpdateCourse(tmpCourse); } } catch (Exception ex) { TempData["CustomError"] = $"Error {(tmpCourse.CourseID == 0 ? "adding" : "updating")} Course: {ex.Message}"; } return(RedirectToAction("ViewCourse", new { courseID = tmpCourse.CourseID })); }
protected void AddCourse_Click(object sender, EventArgs e) { if (Request.QueryString["id"] == null) { addCourseObj.AddCourse(CourseCode.Text, CourseName.Text, CreditHours.Text); Response.Redirect("~/Admin/Courses.aspx"); } else { addCourseObj.UpdateCourse(Request.QueryString["id"], CourseCode.Text, CourseName.Text, CreditHours.Text); Response.Redirect("~/Admin/Courses.aspx"); } }
protected void btnAddStudent_Click(object sender, EventArgs e) { CourseInf courseInf = new CourseInf(txtCourseNumber.Text, ddlCollege.SelectedValue, txtCourseName.Text, Convert.ToSingle(txtXueFen.Text), ddlCourseType.SelectedValue, Convert.ToInt32(txtCourseTime.Text), ddlIsPublic.SelectedValue, txtCourseRemark.Text); course.AddCourse(courseInf, lblMessage); }
public IActionResult OnPost() { try { // in case we have to be on the same page again? Init(); RefreshShownCourses(); if (!ModelState.IsValid) { return(Page()); } if (!int.TryParse(Request.Form["courseId"], out int id)) { return(FailWithMessage("The ID is invalid.")); } // we have enough information for access control if (!AllowedToModify(id)) { return(FailWithMessage("You aren't allowed to change this course.")); } string name = Request.Form["courseTitle"]; string courseCode = Request.Form["courseCode"]; string description = Request.Form["description"]; if (!int.TryParse(Request.Form["credit"], out int credit) || credit < 0) { return(FailWithMessage("The credit is invalid.")); } if (!int.TryParse(Request.Form["lectureHours"], out int lectureHours) || lectureHours < 0) { return(FailWithMessage("The lecture hours are invalid.")); } if (!int.TryParse(Request.Form["labHours"], out int labHours) || labHours < 0) { return(FailWithMessage("The lab hours are invalid.")); } if (!int.TryParse(Request.Form["totalHours"], out int totalHours) || totalHours < 0) { return(FailWithMessage("The total hours are invalid.")); } if (!int.TryParse(Request.Form["examHours"], out int examHours) || examHours < 0) { return(FailWithMessage("The exam hours are invalid.")); } if (!decimal.TryParse(Request.Form["revisionNumber"], out decimal revisionNumber)) { return(FailWithMessage("The revision number is invalid.")); } string program = Request.Form["program"]; if (!bool.TryParse(Request.Form["accreditation"], out bool accreditation)) { return(FailWithMessage("The accreditation is invalid.")); } if (!int.TryParse(Request.Form["semester"], out int semester) || semester < 0) { return(FailWithMessage("The semester is invalid.")); } if (!DateTime.TryParse(Request.Form["startDate"], out DateTime startDate)) { return(FailWithMessage("The start date is invalid.")); } if (!DateTime.TryParse(Request.Form["endDate"], out DateTime endDate)) { return(FailWithMessage("The end date is invalid.")); } if (startDate > endDate) { return(FailWithMessage("The end of the course is before when it starts.")); } if (!int.TryParse(Request.Form["leadStaff"], out int leadStaffId) || leadStaffId < 0) { return(FailWithMessage("The lead staff ID is invalid.")); } Staff leadStaff = new Staff(leadStaffId, "", "lead"); Staff supportStaff = null; //Leave support staff as null unless there was a choice selected (its optional) if (!string.IsNullOrWhiteSpace(Request.Form["supportStaff"])) { if (!int.TryParse(Request.Form["supportStaff"], out int supportStaffId) || supportStaffId < 0) { return(FailWithMessage("The support staff ID is invalid.")); } supportStaff = new Staff(supportStaffId, "", "support"); } List <Prerequisite> prereqs = new List <Prerequisite>(); for (int i = 0; i < Convert.ToInt32(Request.Form["count"]); i++) { Prerequisite prereq = null; //Validation to see if the entered prereq coursecode is valid //If it isn't, the method will return 0 and then it will refresh with a message (should be no courseid of 0) int prereqId = CourseCode.GetIdByCourseCode(Request.Form["prereqCode+" + i]); if (prereqId == 0) { return(FailWithMessage("You entered a invalid Course Code for a Prerequisite")); } //If it returned a valid id, now check if its a coreq or a prereq if (Request.Form["reqRadio+" + i].Equals("prereq")) { prereq = new Prerequisite(id, prereqId, true, false); } else if (Request.Form["reqRadio+" + i].Equals("coreq")) { prereq = new Prerequisite(id, prereqId, false, true); } prereqs.Add(prereq); } if (Add == false) { Course c = new Course(id, name, credit, description, lectureHours, labHours, examHours, totalHours, revisionNumber, program, accreditation); c.UpdateCourse(leadStaff, supportStaff, prereqs); } else if (Add == true) { id = Course.AddCourse(new Course(id, name, credit, description, lectureHours, labHours, examHours, totalHours, revisionNumber, program, accreditation), leadStaff, supportStaff, prereqs); } // XXX: really flawed and prob won't be performant, we need proper course code management var oldCourseCode = !(Add ?? false) ? Course.GetCourseById(id)?.GetCourseCode()?.Code : null; if (courseCode != oldCourseCode) { CourseCode.AddCourseCode(id, new CourseCode(courseCode, startDate, endDate, semester)); } return(ShowAllCourses ? RedirectToPage("ManageCourses", "all") : RedirectToPage("ManageCourses")); } catch (Exception ex) { return(FailWithMessage("There was an exception from the system updating the course;" + "report this to an administrator: " + ex.Message)); } }