public static string CurrentCourseTermLink(this HtmlHelper html, string before, string after)
        {
            AssessTrackDataRepository data = new AssessTrackDataRepository();
            if (html.ViewContext.RouteData.Values["siteShortName"] != null)
            {
                string siteShortName = html.ViewContext.RouteData.Values["siteShortName"].ToString();
                Site site = data.GetSiteByShortName(siteShortName);

                if (site != null)
                {
                    if (html.ViewContext.RouteData.Values["courseTermShortName"] != null)
                    {
                        string courseTermShortName = html.ViewContext.RouteData.Values["courseTermShortName"].ToString();
                        CourseTerm ct = data.GetCourseTermByShortName(site,courseTermShortName);
                        if (ct == null)
                        {
                            return string.Empty;
                        }
                        string courseTermLink = HtmlHelper.GenerateRouteLink(html.ViewContext.RequestContext,
                            html.RouteCollection, ct.Name, null,
                            new System.Web.Routing.RouteValueDictionary(
                                new
                                {
                                    action = "Details",
                                    controller = "CourseTerm",
                                    siteShortName = siteShortName,
                                    courseTermShortName = courseTermShortName
                                }), null);
                        string finallink = before + courseTermLink + after;
                        return finallink;
                    }
                }
            }
            return string.Empty;
        }
Beispiel #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;

            }
        }