コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CourseId,StudentId,Semester,Year,Grade,SeminarUrl,ProjectUrl,ExamPoints,SeminarPoints,ProjectPoints,AdditionalPoints,FinishDate")] 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;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]  = new SelectList(_context.Course, "Id", "Title", enrollment.CourseId);
            ViewData["StudentId"] = new SelectList(_context.Student, "Id", "FirstName", enrollment.StudentId);
            return(View(enrollment));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, StudentsInCourseVM viewmodel)
        {
            if (id != viewmodel.Course.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(viewmodel.Course);
                    await _context.SaveChangesAsync();

                    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(viewmodel.Course.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FirstTeacherID"]  = new SelectList(_context.Set <Teacher>(), "Id", "FullName", viewmodel.Course.FirstTeacherID);
            ViewData["SecondTeacherID"] = new SelectList(_context.Set <Teacher>(), "Id", "FullName", viewmodel.Course.SecondTeacherID);
            return(View(viewmodel));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, TeacherFormVm Vmodel)
        {
            if (id != Vmodel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string uniqueFileName = UploadedFile(Vmodel);

                    Teacher teacher = new Teacher
                    {
                        ProfilePicture = uniqueFileName,
                        Id             = Vmodel.Id,
                        FirstName      = Vmodel.FirstName,
                        LastName       = Vmodel.LastName,
                        Degree         = Vmodel.Degree,
                        AcademicRank   = Vmodel.AcademicRank,
                        OfficeNumber   = Vmodel.OfficeNumber,
                        HireDate       = Vmodel.HireDate,
                        FirstCourses   = Vmodel.FirstCourses,
                        SecondCourses  = Vmodel.SecondCourses
                    };

                    _context.Update(teacher);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TeacherExists(Vmodel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(Vmodel));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, StudentFormVM Vmodel)
        {
            if (id != Vmodel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string uniqueFileName = UploadedFile(Vmodel);

                    Student student = new Student
                    {
                        Id              = Vmodel.Id,
                        FirstName       = Vmodel.FirstName,
                        LastName        = Vmodel.LastName,
                        ProfilePicture  = uniqueFileName,
                        EnrollmentDate  = Vmodel.EnrollmentDate,
                        CurrentSemestar = Vmodel.CurrentSemestar,
                        AcquiredCredits = Vmodel.AcquiredCredits,
                        StudentId       = Vmodel.StudentId,
                        EducationLevel  = Vmodel.EducationLevel,
                        Courses         = Vmodel.Courses
                    };

                    _context.Update(student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(Vmodel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(Vmodel));
        }