예제 #1
0
 /// <summary>
 /// Creates a ClassViewModel for the given class
 /// </summary>
 /// <param name="class">Class to create view-model for</param>
 public ClassViewModel(Class @class)
 {
     if(@class != null)
     {
         Id = @class.Id;
         Title = @class.Title;
         Prefix = @class.Prefix;
         CourseNumber = @class.CourseNumber;
         Section = @class.Section;
         GradeDistribution = @class.GradeDistribution;
         Teacher = new UserViewModel(@class.Teacher);
     }
 }
예제 #2
0
        /// <summary>
        /// Calculates and returns a students grade in a class
        /// </summary>
        /// <param name="student">To student to calculate a grade for</param>
        /// <param name="class">The class that the student is enrolled in</param>
        /// <returns></returns>
        public async Task<float> GetStudentGradeAsync(ApplicationUser student, Class @class)
        {
            WorkItemManager workItemManager = new WorkItemManager(_db);

            var workItems = await workItemManager.GetClassWorkItems(@class);
            var total = 0.0f;

            total += await GetAverageForType(student, workItems, WorkItemType.Exam, @class.GradeDistribution);
            total += await GetAverageForType(student, workItems, WorkItemType.Homework, @class.GradeDistribution);
            total += await GetAverageForType(student, workItems, WorkItemType.Other, @class.GradeDistribution);
            total += await GetAverageForType(student, workItems, WorkItemType.Project, @class.GradeDistribution);
            total += await GetAverageForType(student, workItems, WorkItemType.Quiz, @class.GradeDistribution);

            return total;
        }
예제 #3
0
        /// <summary>
        /// Deletes a students enrollment in a class
        /// </summary>
        /// <param name="class">The class the student is enrolled in or has applied for enrollment</param>
        /// <param name="student">The student to unenroll from the class</param>
        /// <returns>Null if the student is not enrolled in class. Otherwise, returns the
        /// enrollment that was removed</returns>
        /// <remarks>This clears all data associated with the student in this class and
        /// cannot be undone</remarks>
        public async Task<Enrollment> DropStudent(Class @class, ApplicationUser student)
        {
            // Check that the student is actually enrolled
            var status = await _db.Enrollments.Where(e => e.Class.Id == @class.Id && e.Student.Id == student.Id).FirstOrDefaultAsync();
            if(status == null)
            {
                return null;
            }

            // Delete all student related data
            var scoreUnits = await _db.ScoreUnits.Where(sc => sc.Student.Id == student.Id).ToListAsync();
            _db.ScoreUnits.RemoveRange(scoreUnits);
            _db.Enrollments.Remove(status);
            await _db.SaveChangesAsync();

            return status;
        }
예제 #4
0
        /// <summary>
        /// Enrolls a new student into the class
        /// </summary>
        /// <param name="class">Class to enroll the student in</param>
        /// <param name="student">Student to enroll in a class</param>
        /// <returns>Null if the an enrollment has already been created. Otherwise, the
        /// enrollment that was just created.</returns>
        public async Task<Enrollment> RequestEnrollment(Class @class, ApplicationUser student)
        {
            var status = await (from enrollment in _db.Enrollments
                                where enrollment.Student.Id == student.Id && enrollment.Class.Id == @class.Id
                                select enrollment).FirstOrDefaultAsync();

            if(status != null)
            {
                return null;
            }

            // Create the enrollment as pending
            Enrollment newEnroll = new Enrollment { Class = @class, Student = student, Pending = true };
            _db.Enrollments.Add(newEnroll);
            await _db.SaveChangesAsync();

            return newEnroll;
        }
예제 #5
0
        /// <summary>
        /// Creates a new class from the given binding model
        /// </summary>
        /// <param name="classBindingModel">Model containing the details of the class
        /// to create</param>
        /// <returns>Null if teacher could not be found. Otherwise, returns the 
        /// created class</returns>
        public async Task<Class> CreateClass(CreateClassBindingModel classBindingModel)
        {
            var teacher = await _userManager.FindByNameAsync(classBindingModel.TeacherUserName);

            if(teacher == null)
            {
                return null;
            }

            Class @class = new Class
            {
                Title = classBindingModel.Title,
                Prefix = classBindingModel.Prefix,
                CourseNumber = classBindingModel.CourseNumber,
                Section = classBindingModel.Section,
                Teacher = teacher,
                GradeDistribution = classBindingModel.GradeDistribution
            };

            _db.Classes.Add(@class);
            await _db.SaveChangesAsync();
            return @class;
        }
예제 #6
0
 /// <summary>
 /// Returns all students in a class (both pending and accepted)
 /// </summary>
 /// <param name="class">The class to return students for</param>
 /// <returns></returns>
 public async Task<IEnumerable<ApplicationUser>> GetAllStudents(Class @class)
 {
     return await _db.Enrollments
         .Where(e => e.Class.Id == @class.Id)
         .Select(e => e.Student).ToListAsync();
 }
예제 #7
0
 /// <summary>
 /// Returns all students who have been accepted into a class
 /// </summary>
 /// <param name="class">The class to return students for</param>
 /// <returns></returns>
 public async Task<IEnumerable<ApplicationUser>> GetAcceptedStudents(Class @class)
 {
     return await _db.Enrollments.Where(e => e.Class.Id == @class.Id && e.Pending == false).Select(e => e.Student).ToListAsync();
 }
예제 #8
0
 /// <summary>
 /// Returns all non-pending enrollments for the given class
 /// </summary>
 /// <param name="class">Class to return non-pending enrollments for</param>
 /// <returns></returns>
 public async Task<IEnumerable<Enrollment>> GetAcceptedEnrollmentsForClass(Class @class)
 {
     return await _db.Enrollments.Where(e => e.Class.Id == @class.Id && e.Pending == false).Include(e => e.Student).ToListAsync();
 }
예제 #9
0
 /// <summary>
 /// Returns all enrollments both pending and not for a class
 /// </summary>
 /// <param name="class">The class to return the enrollments for</param>
 /// <returns></returns>
 public async Task<IEnumerable<Enrollment>> GetAllEnrollmentsForClass(Class @class)
 {
     return await _db.Enrollments.Where(e => e.Class.Id == @class.Id).Include(e => e.Student).ToListAsync();
 }
예제 #10
0
        /// <summary>
        /// Returns all WorkItems that have been assigned in a class
        /// </summary>
        /// <param name="class">Class to return WorkItems for</param>
        /// <returns></returns>
        public async Task<IEnumerable<WorkItem>> GetClassWorkItems(Class @class)
        {
            if(@class == null)
            {
                return null;
            }

            return await Db.WorkItems.Where(e => e.Class.Id == @class.Id).Include(wi => wi.Class.Teacher).ToListAsync();
        }
예제 #11
0
 /// <summary>
 /// Returns a list of announcements for the given class
 /// </summary>
 /// <param name="class"></param>
 /// <returns></returns>
 public async Task<IEnumerable<Announcement>> GetClassAnnouncements(Class @class)
 {
     return await _db.Announcements.Where(a => a.Class.Id == @class.Id).ToListAsync();
 }