Exemplo n.º 1
0
        public async Task <IActionResult> AddStudentToSubject(int subjectId, int studentId = -1)
        {
            if (_subjectService.DoesSubjectBelongsToStudent(subjectId, studentId))
            {
                return(RedirectToAction("IndexTeacher", new { subjectId = subjectId }));
            }

            if (studentId != -1)
            {
                // studentId checking

                await _subjectService.AddStudentToSubject(subjectId, studentId);
            }

            Teacher teacher = await _authentication.GetCurrentTeacherAsync();

            if (!_subjectService.DoesSubjectBelongsToTeacher(subjectId, teacher.Id))
            {
                return(RedirectToAction("IndexTeacher", new { subjectId = subjectId }));
            }

            Subject subject = _databaseWorker.GetSubjectById(subjectId);
            IEnumerable <Student> availableStudents = await _subjectService.GetStudentsWithoutThisSubject(subject);

            StudentSubjectViewModel model = new StudentSubjectViewModel {
                Subject = subject, Students = availableStudents
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public StudentSubjectView()
        {
            InitializeComponent();
            var vm = new StudentSubjectViewModel();

            this.DataContext = vm;
        }
        // GET: StudentSubjects/Create
        public IActionResult Create()
        {
            var model = new StudentSubjectViewModel()
            {
                Subjects = _context.Subjects.Include(s => s.InstituteProvider).ToList()
            };

            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> ListStudent(int subjectId)
        {
            Teacher teacher = await _authentication.GetCurrentTeacherAsync();

            if (!_subjectService.DoesSubjectBelongsToTeacher(subjectId, teacher.Id))
            {
                return(RedirectToAction("IndexTeacher"));
            }

            Subject subject = _databaseWorker.GetSubjectById(subjectId);

            StudentSubjectViewModel model = new StudentSubjectViewModel {
                Subject = subject, Students = await _subjectService.GetStudentsBySubject(subject)
            };

            return(View(model));
        }
        public async Task <IActionResult> Create(StudentSubjectViewModel model)
        {
            var currentUser    = _context.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);
            var studentSubject = new StudentSubject()
            {
                Description      = model.Description,
                SubjectDifficult = model.SubjectDifficult,
                IsConcluded      = model.IsConcluded,
                SubjectId        = model.SubjectId,
                Student          = currentUser
            };

            if (ModelState.IsValid)
            {
                _context.Add(studentSubject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }