Example #1
0
        /// <summary>
        /// Returns the grades of all students in a class
        /// </summary>
        /// <returns></returns>
        public async Task<IEnumerable<StudentViewModel>> GetGradesForClass(int classId)
        {
            var @class = await _db.Classes.FindAsync(classId);
            if(@class == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No class with id: " + classId));
            }

            var students = await _classManager.GetAcceptedStudents(@class);

            var result = new List<StudentViewModel>();
            foreach(var student in students)
            {
                var viewModel = new StudentViewModel(student);
                viewModel.Grade = await _gradeManager.GetStudentGradeAsync(student, @class);
                result.Add(viewModel);
            }

            return result;
        }
Example #2
0
        public async Task<IHttpActionResult> GetStudentsGrade(string userName, int classId)
        {
            if(userName == null)
            {
                return BadRequest("student parameter must not be empty");
            }

            var @class = await _db.Classes.FindAsync(classId);
            ApplicationUserManager manager = new ApplicationUserManager(new UserStore<ApplicationUser>(_db));
            var student = await manager.FindByEmailAsync(userName);

            if(@class == null || student == null)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Could not match parameters to records"));
            }

            var result = new StudentViewModel(student);
            result.Grade = await _gradeManager.GetStudentGradeAsync(student, @class);

            return Ok(result);
        }