Ejemplo n.º 1
0
        // GET: StudentSubjects/Create
        public IActionResult Create(int?id)
        {
            ViewData["StudId"]  = new SelectList(_context.Student, "StudId", "StudId");
            ViewData["Subject"] = SetSelected.SetSelectedValue(new SelectList(_context.Subject, "SubjectId", "SubjectName"), id.ToString());

            return(View());
        }
Ejemplo n.º 2
0
        // GET: ExamSubjects
        public async Task <IActionResult> Index([FromQuery(Name = "examId")] int examId, [FromQuery(Name = "classId")] int classId, [FromQuery(Name = "subjectId")] int subjectId)
        {
            ViewData["ExamList"]  = SetSelected.SetSelectedValue(new SelectList(_context.Exam, "ExamId", "ExamDesc"), examId.ToString());
            ViewData["ClassList"] = SetSelected.SetSelectedValue(new SelectList(_context.Class, "ClassId", "ClassDesc"), classId.ToString());

            var p_examId  = new SqlParameter("@p0", examId);
            var p_classId = new SqlParameter("@p1", classId);

            if (classId != 0)
            {
                var subjectList = await _context.SubjectList.FromSql("EXEC GetSubjectListByExamIdClassId @p0, @p1", p_examId, p_classId).ToListAsync();

                ViewData["SubjectList"] = SetSelected.SetSelectedValue(new SelectList(subjectList, "SubjectId", "SubjectName"), subjectId.ToString());

                if (subjectId > 0)
                {
                    var p_subjectId = new SqlParameter("@p2", subjectId);
                    var studentList = await _context.ExamStudentList.FromSql("EXEC GetStudentListByExamIdClassIdSubjectId @p0, @p1, @p2", p_examId, p_classId, p_subjectId).ToListAsync();

                    ViewData["StudentList"] = studentList;
                }
            }

            return(View());
        }
Ejemplo n.º 3
0
        // GET: Students
        public async Task <IActionResult> Index(int filter)
        {
            var smartUniContext = _context.Student.Include(s => s.Class).Include(s => s.StudyStatus);

            ViewData["ClassList"] = SetSelected.SetSelectedValue(new SelectList(_context.Class, "ClassId", "ClassDesc"), filter.ToString());

            return(View(await smartUniContext.Where(s => s.ClassId == filter).ToListAsync()));
        }
Ejemplo n.º 4
0
        // GET: ExamSubjects/Create
        public async Task <IActionResult> Create(int id, [FromQuery(Name = "selectedId")] int selectedId)
        {
            ViewData["ExamId"] = id;
            var examList = new SelectList(_context.Exam, "ExamId", "ExamDesc");

            ViewData["ExamList"] = SetSelected.SetSelectedValue(examList, id.ToString());
            var subjectList = new SelectList(_context.Subject, "SubjectId", "SubjectName");

            ViewData["Subject"] = SetSelected.SetSelectedValue(subjectList, selectedId.ToString());

            var studentSubject = await _context.StudentSubject.Include(s => s.Student).Where(s => s.SubjectId == selectedId).ToListAsync();

            PopulateStudentSubjectList(id, studentSubject);
            return(View());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("StudSubjectId,StudId,SubjectId")] StudentSubject studentSubject)
        {
            if (ModelState.IsValid)
            {
                if (_context.StudentSubject.Where(x => x.StudId == studentSubject.StudId && x.SubjectId == studentSubject.SubjectId).CountAsync().Result == 0)
                {
                    _context.Add(studentSubject);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Details", "Subjects", new { id = studentSubject.SubjectId }));
                }
                else
                {
                    ViewData["StudId"]  = new SelectList(_context.Student, "StudId", "StudId");
                    ViewData["Subject"] = SetSelected.SetSelectedValue(new SelectList(_context.Subject, "SubjectId", "SubjectName"), studentSubject.SubjectId.ToString());
                    ViewData["Error"]   = "Student has registered the same subject.";
                    return(View());
                }
            }
            return(RedirectToAction("Details", "Subjects", new { id = studentSubject.SubjectId }));
        }