public ActionResult GetAssessments(Guid id)
        {
            AssessTrackDataRepository repo = new AssessTrackDataRepository();
            CourseTerm term = repo.GetCourseTermByID(id);
            var assessments = from assessment in term.Assessments
                              orderby assessment.Name
                              select new { name = assessment.Name, id = assessment.AssessmentID };

            return Json(assessments);
        }
예제 #2
0
        //Will return false if routeData points to non-existant site or courseterm
        public static bool CheckAuthorization(AuthScope scope, int minLevel, int maxLevel, RouteValueDictionary routeData)
        {
            //RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));
            AssessTrackDataRepository data = new AssessTrackDataRepository();
            string siteShortName;
            Site site = null;
            string courseTermShortName;
            CourseTerm courseTerm = null;
            //HttpContext.Current.

            if (scope != AuthScope.Application)
            {
                //Try to get the site by shortName
                if (routeData["siteShortName"] != null)
                {
                    siteShortName = routeData["siteShortName"].ToString();
                    site = data.GetSiteByShortName(siteShortName);
                }
                //if scope is Site, then {id} should refer to SiteID
                else if (scope != AuthScope.CourseTerm && routeData["id"] != null)
                {
                    try
                    {

                        Guid siteID = new Guid(routeData["id"].ToString());
                        site = data.GetSiteByID(siteID);
                    }
                    catch
                    {
                        //Do nothing here
                        //if this fails, site will be null and the following code will
                        //return SiteNotFound
                    }
                }

                if (site == null)
                {
                    return false;
                }
                if (scope == AuthScope.CourseTerm)
                {
                    //Try to get the site by shortName
                    if (routeData["courseTermShortName"] != null)
                    {
                        courseTermShortName = routeData["courseTermShortName"].ToString();
                        courseTerm = data.GetCourseTermByShortName(site, courseTermShortName);
                    }
                    //if scope is CourseTerm, then {id} should refer to CourseTermID
                    else if (routeData["id"].ToString() != null)
                    {
                        try
                        {

                            Guid courseTermID = new Guid(routeData["id"].ToString());
                            courseTerm = data.GetCourseTermByID(site, courseTermID);
                        }
                        catch
                        {
                            //Do nothing here
                            //if this fails, courseTerm will be null and the following code will
                            //return CourseTermNotFound
                        }
                    }
                    if (courseTerm == null)
                    {

                        return false;
                    }
                }
            }
            //Set up is complete, now check if the user is authorized
            if (CheckAuthorization(HttpContext.Current, site, courseTerm, scope, minLevel, maxLevel))
            {
                return true;
            }
            else
            {
                return false;

            }
        }