/* * 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()); }
/* * 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); }
/* * 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)); }