public async Task <IActionResult> PutStudent(int id, Student student)
        {
            if (id != student.Id)
            {
                return(BadRequest());
            }

            _context.Entry(student).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutTeacher(int id, Teacher teacher)
        {
            if (id != teacher.Id)
            {
                return(BadRequest());
            }

            _context.Entry(teacher).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TeacherExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Degree,AcademicRank,OfficeNumber,HireDate")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(teacher));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("Id,Index,FirstName,LastName,EnrollmentDate,AcquiredCredits,CurrentSemestar,EducationLevel")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("Id,Title,Credits,Semester,Programme,EducationLevel,FirstTeacherId,SecondTeacherId")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FirstTeacherId"]  = new SelectList(_context.Teacher, "Id", "FirstName", course.FirstTeacherId);
            ViewData["SecondTeacherId"] = new SelectList(_context.Teacher, "Id", "FirstName", course.SecondTeacherId);
            return(View(course));
        }
 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));
 }
        /*public async Task<IActionResult> Create([Bind("CourseId,StudentId,Semester,Year,Grade,SeminalUrl,ProjectUrl,ExamPoints,SeminalPoints,ProjectPoints,AdditionalPoints,FinishDate")] Enrollment enrollment)
         * {
         *  if (ModelState.IsValid)
         *  {
         *      _context.Add(enrollment);
         *      await _context.SaveChangesAsync();
         *      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);
         * }*/
        public async Task <IActionResult> Create(int id, NewStudentEnrollmentsViewModel newStudentEnrollmentsViewModel)
        {
            if (ModelState.IsValid)
            {
                IEnumerable <int> listStudents  = newStudentEnrollmentsViewModel.SelectedStudents;
                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, Year = newStudentEnrollmentsViewModel.Enrollments.Year, Semester = newStudentEnrollmentsViewModel.Enrollments.Semester
                    });
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(newStudentEnrollmentsViewModel));
        }
示例#8
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));
        }