Exemplo n.º 1
0
        public ActionResult Assignments(int Id = 0)
        {
            int userId = int.Parse(Session["UserId"].ToString());
            List <AssignmentItem> assignments = new List <AssignmentItem>();

            using (EastWoodEntities db = new EastWoodEntities())
            {
                int studentId = db.Students.Where(w => w.UserId == userId).Select(s => s.StudentId).FirstOrDefault();
                if (studentId == 0)
                {
                    return(Redirect("/"));
                }
                List <Assignment> items = new List <Assignment>();
                if (Id == 0)
                {
                    items = db.Assignments
                            .Join(
                        db.Subjects,
                        a => a.SubjectId,
                        s => s.SubjectId,
                        (a, s) => new { Subject = s, Assignment = a }
                        )
                            .Join(
                        db.Semesters,
                        asSub => asSub.Subject.SemesterId,
                        sem => sem.SemesterId,
                        (asSub, sem) => new { Semester = sem, Assignment = asSub.Assignment }
                        )
                            .Join(
                        db.StudentCourses.Where(w => w.StudentId == studentId),
                        asSubCourse => asSubCourse.Semester.CourseId,
                        sc => sc.CourseId,
                        (asSubCourse, sc) => new { Assignment = asSubCourse.Assignment }
                        )
                            .Select(s => s.Assignment)
                            .ToList();
                }
                else
                {
                    items = db.Assignments.Where(w => w.SubjectId == Id).ToList();
                }
                foreach (var item in items)
                {
                    AssignmentItem assignment = new AssignmentItem();
                    assignment.Assignment      = item;
                    assignment.Subject         = item.Subject;
                    assignment.AssignmentMarks = MarksHelper.GetMarksForAssignment(item.AssignmentId, studentId);
                    assignment.AssignmentGrade = MarksHelper.GetGradeForAssignment(item.AssignmentId, studentId);
                    assignments.Add(assignment);
                }
            }
            ViewBag.SubjectId = Id;
            return(View(assignments));
        }
 public ActionResult SetMarks(int Id, int Marks, int AssignmentId, string Comment)
 {
     using (EastWoodEntities db = new EastWoodEntities())
     {
         var upload = db.AssignmentUploads.Where(w => w.AssignmentUploadId == Id).FirstOrDefault();
         if (upload != null)
         {
             upload.AssignmentUploadMarks           = Marks;
             upload.AssignmentUploadGrade           = MarksHelper.GetGrade(Marks);
             upload.AssignmentUploadLecturerComment = Comment;
             db.SaveChanges();
         }
     }
     return(Redirect("/Admin/AssignmentUploads/" + AssignmentId));
 }
Exemplo n.º 3
0
        public ActionResult Index(int Id = 0)
        {
            HomePageViewModel viewModel = new HomePageViewModel();

            ViewBag.SelectedCourseId = Id;
            int userId = int.Parse(Session["UserId"].ToString());

            viewModel.Courses = GetCoursesViewModel(userId);
            if (viewModel.Courses != null && viewModel.Courses.Courses.Count > Id)
            {
                viewModel.Semesters = GetSemesters(viewModel.Courses.Courses[Id].CourseId);
                viewModel.Subjects  = new List <Subject>();
                foreach (var sem in viewModel.Semesters)
                {
                    viewModel.Subjects.AddRange(GetSubjectsBySemester(sem.SemesterId));
                }
            }
            using (EastWoodEntities db = new EastWoodEntities())
            {
                var student = db.Students.Where(w => w.UserId == userId).FirstOrDefault();
                if (student != null && viewModel.Subjects != null && viewModel.Semesters != null)
                {
                    // get marks for student for subjects
                    foreach (var sub in viewModel.Subjects)
                    {
                        sub.StudentAvgMarksForSubject = MarksHelper.GetAvgMarksForSubject(sub.SubjectId, student.StudentId);
                        sub.StudentGradeForSubject    = MarksHelper.GetGradeForSubject(sub.SubjectId, student.StudentId);
                    }
                    // get marks for student for semesters
                    foreach (var sem in viewModel.Semesters)
                    {
                        sem.StudentGradeForSemester = MarksHelper.GetGradeForSemester(sem.SemesterId, student.StudentId);
                    }
                }
            }

            return(View(viewModel));
        }