Exemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            IList <ExamViewModel> exams = new List <ExamViewModel>();

            if (User.Role() == "Administrator")
            {
                exams = _repos.Exams
                        .ListWith("Unit")
                        .Select(TransformFuncs.ToViewModel())
                        .ToList();

                return(Ok(exams));
            }

            AppUser user = await _usermanager.GetUserAsync(User);

            if (User.Role() == "Lecturer")
            {
                exams = _dataManager.MyExams <Lecturer>(user.AccountId);
            }
            else if (User.Role() == "Student")
            {
                exams = _dataManager.MyExams <Student>(user.AccountId);
            }

            return(Ok(exams));
        }
Exemplo n.º 2
0
        public IActionResult GetByUnit(int id)
        {
            IList <ExamViewModel> exams = new List <ExamViewModel>();

            exams = _repos.Units.GetWith(id, "Exams", "Exams.Unit")
                    ?.Exams
                    .Select(TransformFuncs.ToViewModel())
                    .TakeWhile(x => x != null)
                    .ToList();

            return(Ok(exams));
        }