Skip to content

Commit

Permalink
fixe semesters
Browse files Browse the repository at this point in the history
  • Loading branch information
a.hosseini committed May 17, 2024
1 parent 0e6313f commit 81fdd19
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
Binary file modified Course Scheduler/Course_SchedulerDB.db
Binary file not shown.
Binary file modified Course Scheduler/Course_SchedulerDB.db-shm
Binary file not shown.
Binary file modified Course Scheduler/Course_SchedulerDB.db-wal
Binary file not shown.
21 changes: 16 additions & 5 deletions Course Scheduler/Views/Semester/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ViewData["Title"] = "Create";
var json = Json.Serialize(((List<Course>)ViewData["Courses"]).Select(c => c.Name));
var reqIdjson = Json.Serialize(((List<Course>)ViewData["Courses"]).Select(c => c.ID));
var courseCode = Json.Serialize(((List<Course>)ViewData["Courses"]).Select(c => c.CourseCode));

}

Expand Down Expand Up @@ -60,24 +61,34 @@
var Courses = @json;
var requiredCourseIds = @reqIdjson;
console.log(RequiredCourse);
var courseCode = @courseCode;
console.log(Courses);
console.log(requiredCourseIds);
console.log(courseCode);
function addItem() {
console.log("test");
// 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);
Expand Down
29 changes: 20 additions & 9 deletions Course Scheduler/Views/Semester/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

@{
ViewData["Title"] = "Edit";
var json = Json.Serialize(((List<Course>)ViewData["Courses"]).Select(c => c.Name));
var reqIdjson = Json.Serialize(((List<Course>)ViewData["Courses"]).Select(c => c.ID));
var courses = (List<Course>)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));

}

Expand Down Expand Up @@ -32,7 +34,7 @@
@foreach (var item in Model.CoursesId)
{
<li class="list-group-item d-flex justify-content-between align-items-center">
@(((List<Course>)ViewData["Course"]).First(c => c.ID == item).Name)
@(courses.First(c => c.ID == item).Name)
<input type="hidden" value="@item" class="requiredCourses">
<button class="btn btn-sm btn-outline-danger" type="button" onclick="RemoveItem(this)">Remove</button>
</li>
Expand Down Expand Up @@ -69,24 +71,34 @@
var Courses = @json;
var requiredCourseIds = @reqIdjson;
console.log(RequiredCourse);
var courseCode = @courseCode;
console.log(Courses);
console.log(requiredCourseIds);
console.log(courseCode);
function addItem() {
console.log("test");
// 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);
Expand All @@ -112,7 +124,6 @@
this.parentNode.remove();
}
</script>

@{
await Html.RenderPartialAsync("_ValidationScriptsPartial");
}
Expand Down

0 comments on commit 81fdd19

Please sign in to comment.