Ejemplo n.º 1
0
        public GradeSection(AssessmentType assessmentType, Profile profile, AssessTrackDataRepository repo, bool includeExtraCredit, DateTime date)
        {
            AssessmentType = assessmentType;
            TotalPoints = MaxPoints = 0;
            Grades = new List<Grade>();
            CourseTermMember member = repo.GetCourseTermMemberByMembershipID(assessmentType.CourseTerm, profile.MembershipID);
            List<Assessment> assessments = repo.GetAllNonTestBankAssessments(assessmentType.CourseTerm, includeExtraCredit, assessmentType, member).Where(test => test.DueDate.CompareTo(date) < 0).ToList();
            foreach (Assessment assessment in assessments)
            {
                Grade grade = new Grade(assessment, profile);
                Grades.Add(grade);

                if ((grade.SubmissionRecord != null && grade.SubmissionRecord.GradedBy != null) ||
                    (DateTime.Now.CompareTo(assessment.DueDate) > 0 && grade.SubmissionRecord == null))
                {
                    MaxPoints += assessment.Weight;
                    TotalPoints += grade.Points;
                }
            }
            //if (TotalPoints > 0 && MaxPoints == 0) //if everything is extra credit
            //{
            //    MaxPoints = 1; //to avoid division by zero
            //}

            if (MaxPoints == 0)
            {
                Percentage = 0;
                Weight = 0;
            }
            else
            {
                Percentage = (TotalPoints / MaxPoints) * 100;
                Weight = assessmentType.Weight;
            }
        }
Ejemplo n.º 2
0
 public static bool CheckAuthorization(HttpContext httpContext, Site site, CourseTerm courseTerm, AuthScope scope, int minLevel, int maxLevel)
 {
     AssessTrackDataRepository data = new AssessTrackDataRepository();
     if (httpContext == null)
     {
         throw new ArgumentNullException("httpContext");
     }
     IPrincipal user = httpContext.User;
     if (!user.Identity.IsAuthenticated)
     {
         return false;
     }
     //Get the user's profile and see if they have
     //the required access level
     Profile profile = data.GetLoggedInProfile();
     switch (scope)
     {
         case AuthScope.Application:
             {
                 if (profile.AccessLevel < minLevel || profile.AccessLevel > maxLevel)
                     return false;
                 break;
             }
         case AuthScope.Site:
             {
                 SiteMember member = data.GetSiteMemberByMembershipID(site,profile.MembershipID);
                 if (member == null ||
                     (member.AccessLevel < minLevel || member.AccessLevel > maxLevel))
                     return false;
             }
             break;
         case AuthScope.CourseTerm:
             {
                 CourseTermMember member = data.GetCourseTermMemberByMembershipID(courseTerm, profile.MembershipID);
                 if (member == null ||
                     (member.AccessLevel < minLevel || member.AccessLevel > maxLevel))
                     return false;
             }
             break;
         default:
             //TODO Do some logging here maybe?
             return false;
     }
     return true;
 }
Ejemplo n.º 3
0
        public static bool IsCurrentStudentOrUserIsAdmin(CourseTerm ct, Guid requestedID)
        {
            try
            {
                AssessTrackDataRepository repo = new AssessTrackDataRepository();

                CourseTermMember member = repo.GetCourseTermMemberByMembershipID(ct, UserHelpers.GetCurrentUserID());

                if (member == null)
                {
                    return false;
                }
                else if (member.AccessLevel < 2 && member.MembershipID != requestedID)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch
            {
                return false;
            }
        }