Пример #1
0
 /*
  * Fetches the courses the user is enrolled in, and returns the user's role in the course as well.
  */
 public IEnumerable <Course> GetCoursesForUserWithRole(string userId, CoderRole role)
 {
     return((from c in db.Courses
             join u in db.UserCourses on c.Id equals u.CourseId
             where u.UserId == userId && u.CoderRole == role
             select c).ToList());
 }
Пример #2
0
        /*
         * Checks if the user is enrolled in the course, or has administrative rights.
         */
        public bool HasRoleInCourse(int?id, string userId, bool isAdmin, CoderRole role)
        {
            if (!isAdmin)
            {
                var userCourse = db.UserCourses.Where(i => i.CourseId == id && i.UserId == userId).FirstOrDefault();

                if (userCourse != null)
                {
                    return(userCourse.CoderRole == role);
                }
            }
            return(false);
        }
Пример #3
0
 /*
  * Checks if the user is enrolled in any course, or has administrative rights.
  */
 public bool HasSuperRoleInAnyCourse(string userId, bool isAdmin, CoderRole role)
 {
     return(isAdmin || db.UserCourses.Where(i => i.UserId == userId).Any(x => x.CoderRole == role));
 }