public ActionResult Documents(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            Schedule schedule = repository.Schedule(id);

            if (schedule == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            string          userId    = User.Identity.GetUserId();
            List <Document> documents = schedule.Course.Documents.ToList();

            UsersRepository usersRepo = new UsersRepository();
            string          roleName  = usersRepo.GetUserRole(userId).Name;

            if (roleName == RoleConstants.Student)
            {
                // Any student is allowed to see documents for the current course, as long as the
                // given student takes part of that course
                if (!repository.TakesPart(userId, (int)id))
                {
                    return(RedirectToAction("Index", "Home"));
                }

                // But only documents visible to Students are displayed
                documents = documents.Where(d => d.VisibleFor.Name == RoleConstants.Student).ToList();
            }
            else if (roleName == RoleConstants.Teacher)
            {
                // Any teacher is allowed to see documents for the current course, as long as the
                // given teacher is in charge of that course
                if (!repository.IsInCharge(userId, (int)id))
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (documents.Count == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(View(documents.Select(d => new DocumentsScheduleVM
            {
                Document = d,
                UploadersRole = usersRepo.GetUserRole(d.Uploader.Id).Name
            })));
        }