public ActionResult LectureNotes(int Id = 0)
        {
            List <LectureNoteItem> lectureNotes = new List <LectureNoteItem>();

            using (EastWoodEntities db = new EastWoodEntities())
            {
                List <LectureNote> items = new List <LectureNote>();
                if (Id == 0)
                {
                    items = db.LectureNotes.ToList();
                }
                else
                {
                    items = db.LectureNotes.Where(w => w.SubjectId == Id).ToList();
                }
                foreach (var item in items)
                {
                    LectureNoteItem note = new LectureNoteItem();
                    note.LectureNote = item;
                    note.Subject     = item.Subject;
                    note.Attachments = db.Attachments.
                                       Where(w => w.AttachmentReferenceId == item.LectureNoteid && w.AttachmentReferenceType == AttachmentReferenceTypes.LECTURE_NOTE)
                                       .ToList();
                    lectureNotes.Add(note);
                }
            }
            ViewBag.SubjectId = Id;
            return(View(lectureNotes));
        }
Exemplo n.º 2
0
        public ActionResult LectureNotes(int Id = 0)
        {
            int userId = int.Parse(Session["UserId"].ToString());
            List <LectureNoteItem> lectureNotes = new List <LectureNoteItem>();

            using (EastWoodEntities db = new EastWoodEntities())
            {
                List <LectureNote> items = new List <LectureNote>();
                if (Id == 0)
                {
                    int studentId = db.Students.Where(w => w.UserId == userId).Select(s => s.StudentId).FirstOrDefault();
                    if (studentId == 0)
                    {
                        items = db.LectureNotes.ToList();
                    }
                    else
                    {
                        items = db.LectureNotes
                                .Where(w => w.Subject.Semester.Course.StudentCourses.Where(w2 => w2.StudentId == studentId).Count() > 0)
                                .ToList();
                    }
                }
                else
                {
                    items = db.LectureNotes.Where(w => w.SubjectId == Id).ToList();
                }
                foreach (var item in items)
                {
                    LectureNoteItem note = new LectureNoteItem();
                    note.LectureNote = item;
                    note.Subject     = item.Subject;
                    note.Attachments = db.Attachments.
                                       Where(w => w.AttachmentReferenceId == item.LectureNoteid && w.AttachmentReferenceType == AttachmentReferenceTypes.LECTURE_NOTE)
                                       .ToList();
                    lectureNotes.Add(note);
                }
            }
            ViewBag.SubjectId = Id;
            return(View(lectureNotes));
        }