Esempio n. 1
0
        /// <summary>
        /// Returns all the ScoreUnits associated with the given WorkItem
        /// </summary>
        /// <param name="workItem">WorkItem for which to return ScoreUnits</param>
        /// <returns>Creates new ScoreUnits for all students who have none</returns>
        public async Task<IEnumerable<ScoreUnit>> GetScoreUnits(WorkItem workItem)
        {
            ClassManager classManager = new ClassManager(_db, _userManager);
            var students = await classManager.GetAcceptedStudents(workItem.Class);

            var newScoreUnits = new List<ScoreUnit>();
            var scoreUnits = await _db.ScoreUnits
                .Include(su => su.Student)
                .Where(su => su.WorkItem.Id == workItem.Id).ToDictionaryAsync(su => su.Student.Id);

            // Create new ScoreUnits for those who don't have one
            foreach(var student in students)
            {
                if(!scoreUnits.ContainsKey(student.Id))
                {
                    var newScoreUnit = new ScoreUnit();
                    newScoreUnit.WorkItem = workItem;
                    newScoreUnit.Student = student;
                    newScoreUnit.Grade = null;

                    newScoreUnits.Add(newScoreUnit);
                }
            }

            var addedScoreUnits = _db.ScoreUnits.AddRange(newScoreUnits);
            await _db.SaveChangesAsync();

            // Convert dictionary to list and add new ScoreUnits
            var result = scoreUnits.Select(kvp => kvp.Value).ToList();
            result.AddRange(addedScoreUnits);
            return result;
        }
Esempio n. 2
0
        /// <summary>
        /// Shows the details of the user with the given user name
        /// </summary>
        /// <param name="userName"></param>
        public async Task<ActionResult> Details(string userName)
        {
            var teacher = await userManager.FindByEmailAsync(userName);

            ClassManager manager = new ClassManager(db);
            var classes = await manager.GetUserClasses(teacher);
            ViewBag.Classes = classes;

            return View(teacher);
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a new default ClassesController
 /// </summary>
 public ClassesController()
 {
     _db = new ApplicationDbContext();
     _userManager = new ApplicationUserManager(new UserStore<ApplicationUser>(_db));
     _classManager = new ClassManager(_db);
 }
Esempio n. 4
0
 /// <summary>
 /// Creates a new default GradesController
 /// </summary>
 public GradesController()
 {
     _db = new ApplicationDbContext();
     _gradeManager = new GradeManager(_db);
     _classManager = new ClassManager(_db);
 }