//GET : CurricularGrades/AddSubjects/5
        public async Task <IActionResult> AddSubject(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var subjectsList = _context.Subjects
                               .Include(s => s.InstituteProvider)
                               .ToList();


            var model = new CurricularGradeViewModel()
            {
                Subjects          = subjectsList,
                CurricularGradeId = (int)id
            };

            return(View(model));
        }
        public async Task <IActionResult> AddSubject(int id, CurricularGradeViewModel model)
        {
            var curricularGrade = _context.CurricularGrades
                                  .Include(c => c.Subjects)
                                  .SingleOrDefault(c => c.Id == id);

            if (curricularGrade == null)
            {
                return(NotFound());
            }

            var subject = _context.Subjects.SingleOrDefault(s => s.Id == model.SubjectId);

            if (subject == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    curricularGrade.Subjects.Add(subject);
                    _context.Update(curricularGrade);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CurricularGradeExists(curricularGrade.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }