diff --git a/Course Scheduler/Course_SchedulerDB.db b/Course Scheduler/Course_SchedulerDB.db index a6c28f2..ddf11da 100644 Binary files a/Course Scheduler/Course_SchedulerDB.db and b/Course Scheduler/Course_SchedulerDB.db differ diff --git a/Course Scheduler/Course_SchedulerDB.db-shm b/Course Scheduler/Course_SchedulerDB.db-shm index 9e94ce0..2f488d9 100644 Binary files a/Course Scheduler/Course_SchedulerDB.db-shm and b/Course Scheduler/Course_SchedulerDB.db-shm differ diff --git a/Course Scheduler/Course_SchedulerDB.db-wal b/Course Scheduler/Course_SchedulerDB.db-wal index 55a4116..0fe67d4 100644 Binary files a/Course Scheduler/Course_SchedulerDB.db-wal and b/Course Scheduler/Course_SchedulerDB.db-wal differ diff --git a/Course Scheduler/Views/Semester/Create.cshtml b/Course Scheduler/Views/Semester/Create.cshtml index d911636..3bcb5a2 100644 --- a/Course Scheduler/Views/Semester/Create.cshtml +++ b/Course Scheduler/Views/Semester/Create.cshtml @@ -5,6 +5,7 @@ ViewData["Title"] = "Create"; var json = Json.Serialize(((List)ViewData["Courses"]).Select(c => c.Name)); var reqIdjson = Json.Serialize(((List)ViewData["Courses"]).Select(c => c.ID)); + var courseCode = Json.Serialize(((List)ViewData["Courses"]).Select(c => c.CourseCode)); } @@ -60,8 +61,10 @@ var Courses = @json; var requiredCourseIds = @reqIdjson; - console.log(RequiredCourse); + var courseCode = @courseCode; + console.log(Courses); console.log(requiredCourseIds); + console.log(courseCode); function addItem() { @@ -69,15 +72,23 @@ // Get the text from the input field var newItemText = document.getElementById("newItem").value; var indexOfNewItemText = Courses.indexOf(newItemText); - if (!newItemText || indexOfNewItemText === -1) return; // Prevent empty items + var indexOfNewItemCode = courseCode.indexOf(newItemText); + if (!newItemText || (indexOfNewItemText === -1 && indexOfNewItemCode==-1)) return; // Prevent empty items // Create a new list item element var newListItem = document.createElement("li"); newListItem.classList.add("list-group-item", "d-flex", "justify-content-between", "align-items-center"); - newListItem.textContent = newItemText; - + if (indexOfNewItemCode == -1) { + newListItem.textContent = newItemText; + } else { + newListItem.textContent = Courses[indexOfNewItemCode]; + } var newIput = document.createElement("input"); - newIput.value = requiredCourseIds[indexOfNewItemText]; + if (indexOfNewItemCode == -1) { + newIput.value = requiredCourseIds[indexOfNewItemText]; + }else{ + newIput.value = requiredCourseIds[indexOfNewItemCode]; + } newIput.type = "hidden"; newIput.classList.add("CoursesId"); newListItem.appendChild(newIput); diff --git a/Course Scheduler/Views/Semester/Edit.cshtml b/Course Scheduler/Views/Semester/Edit.cshtml index 49d76b9..c176e01 100644 --- a/Course Scheduler/Views/Semester/Edit.cshtml +++ b/Course Scheduler/Views/Semester/Edit.cshtml @@ -3,8 +3,10 @@ @{ ViewData["Title"] = "Edit"; - var json = Json.Serialize(((List)ViewData["Courses"]).Select(c => c.Name)); - var reqIdjson = Json.Serialize(((List)ViewData["Courses"]).Select(c => c.ID)); + var courses = (List)ViewData["Courses"]; + var json = Json.Serialize((courses).Select(c => c.Name)); + var reqIdjson = Json.Serialize((courses).Select(c => c.ID)); + var courseCode = Json.Serialize((courses).Select(c => c.CourseCode)); } @@ -32,7 +34,7 @@ @foreach (var item in Model.CoursesId) {
  • - @(((List)ViewData["Course"]).First(c => c.ID == item).Name) + @(courses.First(c => c.ID == item).Name)
  • @@ -69,8 +71,10 @@ var Courses = @json; var requiredCourseIds = @reqIdjson; - console.log(RequiredCourse); + var courseCode = @courseCode; + console.log(Courses); console.log(requiredCourseIds); + console.log(courseCode); function addItem() { @@ -78,15 +82,23 @@ // Get the text from the input field var newItemText = document.getElementById("newItem").value; var indexOfNewItemText = Courses.indexOf(newItemText); - if (!newItemText || indexOfNewItemText === -1) return; // Prevent empty items + var indexOfNewItemCode = courseCode.indexOf(newItemText); + if (!newItemText || (indexOfNewItemText === -1 && indexOfNewItemCode == -1)) return; // Prevent empty items // Create a new list item element var newListItem = document.createElement("li"); newListItem.classList.add("list-group-item", "d-flex", "justify-content-between", "align-items-center"); - newListItem.textContent = newItemText; - + if (indexOfNewItemCode == -1) { + newListItem.textContent = newItemText; + } else { + newListItem.textContent = Courses[indexOfNewItemCode]; + } var newIput = document.createElement("input"); - newIput.value = requiredCourseIds[indexOfNewItemText]; + if (indexOfNewItemCode == -1) { + newIput.value = requiredCourseIds[indexOfNewItemText]; + } else { + newIput.value = requiredCourseIds[indexOfNewItemCode]; + } newIput.type = "hidden"; newIput.classList.add("CoursesId"); newListItem.appendChild(newIput); @@ -112,7 +124,6 @@ this.parentNode.remove(); } - @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }