public static IList <string> GetAllAccessRoles(User user, object entity)
        {
            IList <string> accessRoles = new List <string>();

            if (entity == null)
            {
                foreach (Role role in user.Roles)
                {
                    accessRoles.Add(role.Name);
                }
                return(accessRoles);
            }
            switch (entity.GetType().BaseType.Name)
            {
            case "Course":
                Course course = (Course)entity;
                if (user.Equals(course.Teacher.User))
                {
                    accessRoles.Add("Teacher");
                }
                if (user.GetTutor() != null)
                {
                    Tutor authorizedTutor = user.GetTutor();
                    foreach (Lesson otherLesson in authorizedTutor.Lessons)
                    {
                        if (course.Equals(otherLesson.Assignment.Course))
                        {
                            accessRoles.Add("Tutor");
                            break;
                        }
                    }
                }
                if (user.GetStudent() != null)
                {
                    accessRoles.Add("Student");
                }
                return(accessRoles);

            case "Assignment":
                Assignment assignment = (Assignment)entity;
                if (user.Equals(assignment.Course.Teacher.User))
                {
                    accessRoles.Add("Teacher");
                }
                if (user.GetTutor() != null)
                {
                    Tutor authorizedTutor = user.GetTutor();
                    foreach (Lesson otherLesson in authorizedTutor.Lessons)
                    {
                        if (assignment.Equals(otherLesson.Assignment))
                        {
                            accessRoles.Add("Tutor");
                            break;
                        }
                    }
                }
                if (user.GetStudent() != null)
                {
                    Student authorizedStudent = user.GetStudent();
                    foreach (GroupMembership membership in authorizedStudent.GroupMemberships)
                    {
                        if (membership.Group.Lesson.Assignment.Equals(assignment))
                        {
                            accessRoles.Add("Student");
                            break;
                        }
                    }
                }
                return(accessRoles);

            case "Lesson":
                Lesson lesson = (Lesson)entity;
                if (user.Equals(lesson.Assignment.Course.Teacher.User))
                {
                    accessRoles.Add("Teacher");
                }
                if (user.GetTutor() != null)
                {
                    Tutor authorizedTutor = user.GetTutor();
                    if (authorizedTutor.Equals(lesson.Tutor))
                    {
                        accessRoles.Add("Tutor");
                    }
                }
                if (user.GetStudent() != null)
                {
                    Student authorizedStudent = user.GetStudent();
                    foreach (GroupMembership membership in authorizedStudent.GroupMemberships)
                    {
                        if (lesson.Equals(membership.Group.Lesson))
                        {
                            accessRoles.Add("Student");
                            break;
                        }
                    }
                }
                return(accessRoles);

            case "Group":
                Models.Group group = (Models.Group)entity;
                if (user.Equals(group.Lesson.Assignment.Course.Teacher.User))
                {
                    accessRoles.Add("Teacher");
                }
                if (user.GetTutor() != null)
                {
                    Tutor authorizedTutor = user.GetTutor();
                    if (authorizedTutor.Equals(group.Lesson.Tutor))
                    {
                        accessRoles.Add("Tutor");
                    }
                }
                if (user.GetStudent() != null)
                {
                    Student authorizedStudent = user.GetStudent();
                    foreach (GroupMembership membership in authorizedStudent.GroupMemberships)
                    {
                        if (group.Equals(membership.Group))
                        {
                            accessRoles.Add("Student");
                            break;
                        }
                    }
                }
                return(accessRoles);

            default:
                return(accessRoles);
            }
        }