public async Task <IActionResult> Edit(int id, string pom, [Bind("Id,Semester,Year,Grade,SeminalUrl,ProjectUrl,ExamPoints,SeminalPoints,ProjectPoints,AdditionalPoints,FinishDate,CourseId,StudentId")] Enrollment enrollment) { if (id != enrollment.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(enrollment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EnrollmentExists(enrollment.Id)) { return(NotFound()); } else { throw; } } if (pom.Equals("admin")) { return(RedirectToAction("Index")); } return(RedirectToAction("CourseStudents", new { id = enrollment.CourseId })); } ViewData["CourseId"] = new SelectList(_context.Course, "Id", "Title", enrollment.CourseId); ViewData["StudentId"] = new SelectList(_context.Student, "Id", "FullName", enrollment.StudentId); if (pom.Equals("admin")) { return(View("EditByAdmin", enrollment)); } else { return(View(enrollment)); } }
public async Task <IActionResult> Edit(int id, StudentFormViewModel vm) { if (id != vm.Id) { return(NotFound()); } if (ModelState.IsValid) { try { string uniqueFileName = UploadedFile(vm); Student student = new Student { Id = vm.Id, FirstName = vm.FirstName, LastName = vm.LastName, ProfilePicture = uniqueFileName, EnrollmentDate = vm.EnrollmentDate, CurrentSemestar = vm.CurrentSemestar, AcquiredCredits = vm.AcquiredCredits, Index = vm.Index, EducationLevel = vm.EducationLevel, Courses = vm.Courses }; _context.Update(student); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(vm.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(vm)); }
public async Task <IActionResult> Edit(int id, TeacherFormViewModel vm) { if (id != vm.Id) { return(NotFound()); } if (ModelState.IsValid) { try { string uniqueFileName = UploadedFile(vm); Teacher teacher = new Teacher { Id = vm.Id, FirstName = vm.FirstName, LastName = vm.LastName, ProfilePicture = uniqueFileName, Degree = vm.Degree, AcademicRank = vm.AcademicRank, OfficeNumber = vm.OfficeNumber, HireDate = vm.HireDate, Courses_first = vm.Courses_first, Courses_second = vm.Courses_second }; _context.Update(teacher); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeacherExists(vm.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(vm)); }
public async Task <IActionResult> Edit(int id, /*CourseStudentViewModel viewmodel*/ [Bind("Id,Title,Credits,Semester,Programme,EducationLevel,FirstTeacherId,SecondTeacherId")] Course course) { if (id != course.Id /*viewmodel.Course.Id*/) { return(NotFound()); } if (ModelState.IsValid) { try { /* _context.Update(viewmodel.Course); */ _context.Update(course); await _context.SaveChangesAsync(); //Faza1 /*IEnumerable<int> listStudents = viewmodel.SelectedStudents; * IQueryable<Enrollment> toBeRemoved = _context.Enrollment.Where(s => !listStudents.Contains(s.StudentId) && s.CourseId == id); * _context.Enrollment.RemoveRange(toBeRemoved); * * IEnumerable<int> existStudents = _context.Enrollment.Where(s=> listStudents.Contains(s.StudentId) && s.CourseId == id).Select(s=>s.StudentId); * IEnumerable<int> newStudents = listStudents.Where(s => !existStudents.Contains(s)); * foreach (int studentId in newStudents) * _context.Enrollment.Add(new Enrollment { StudentId = studentId, CourseId = id });*/ await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(course.Id /*viewmodel.Course.Id*/)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FirstTeacherId"] = new SelectList(_context.Teacher, "Id", "FullName", /*viewmodel.Course.*/ course.FirstTeacherId); ViewData["SecondTeacherId"] = new SelectList(_context.Teacher, "Id", "FullName", course.SecondTeacherId); return(View(/*viewmodel*/ course)); }