Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Degree,AcademicRank,OfficeNumber,HireDate")] Teacher teacher)
        {
            if (id != teacher.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(teacher);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TeacherExists(teacher.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(teacher));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Index,FirstName,LastName,EnrollmentDate,AcquiredCredits,CurrentSemestar,EducationLevel")] Student student)
        {
            if (id != student.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Пример #3
0
 public async Task <IActionResult> StudentEdit(int id, [Bind("Id,Grade,ExamPoints,SeminalPoints,ProjectPoints,AdditionalPoints,FinishDate,ProjectUrl,SeminalUrl,Year,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;
             }
         }
         return(RedirectToAction("StudentSubject", new { id = enrollment.CourseId }));
     }
     ViewData["CourseId"]  = new SelectList(_context.Course, "Id", "Title", enrollment.CourseId);
     ViewData["StudentId"] = new SelectList(_context.Student, "Id", "FirstName", enrollment.StudentId);
     return(View(enrollment));
 }
Пример #4
0
        public async Task <IActionResult> CourseEdit(int id, CourseStudentViewModel coursestudentviewmodel)
        {
            if (id != coursestudentviewmodel.Course.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(coursestudentviewmodel.Course);
                    await _context.SaveChangesAsync();

                    IEnumerable <int>       listStudents = coursestudentviewmodel.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(coursestudentviewmodel.Course.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(CourseIndex)));
            }
            ViewData["FirstTeacherId"]  = new SelectList(_context.Teacher, "Id", "FullName", coursestudentviewmodel.Course.FirstTeacherId);
            ViewData["SecondTeacherId"] = new SelectList(_context.Teacher, "Id", "FullName", coursestudentviewmodel.Course.SecondTeacherId);
            return(View(coursestudentviewmodel));
        }
Пример #5
0
        public async Task <IActionResult> Edit(int id, EnrollmentViewModel enrollment)
        {
            if (id != enrollment.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    string uniqueFileName = UploadedFile(enrollment);

                    Enrollment enrollmentvm = new Enrollment
                    {
                        Id               = enrollment.Id,
                        Semester         = enrollment.Semester,
                        Year             = enrollment.Year,
                        Grade            = enrollment.Grade,
                        ProjectUrl       = enrollment.ProjectUrl,
                        SeminalPoints    = enrollment.SeminalPoints,
                        ProjectPoints    = enrollment.ProjectPoints,
                        AdditionalPoints = enrollment.AdditionalPoints,
                        ExamPoints       = enrollment.ExamPoints,
                        FinishDate       = enrollment.FinishDate,
                        CourseId         = enrollment.CourseId,
                        StudentId        = enrollment.StudentId,
                        SeminalUrl       = uniqueFileName
                    };
                    _context.Update(enrollmentvm);
                    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));
        }