Exemplo n.º 1
0
        public JsonResult AssignTo(int CourseID, int TeacherID)
        {
            CourseRepository        courseRepository  = new CourseRepository();
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();
            TeacherRepository       teacherRepository = new TeacherRepository();
            Teacher teacher = new Teacher();

            teacher = teacherRepository.GetById(TeacherID);
            List <SelectListItem> listSubjects = new List <SelectListItem>();
            var allSubjects = courseSubjectRepo.GetAll(filter: s => s.CourseID == CourseID);

            foreach (var item in allSubjects)
            {
                if (teacher.CourseSubject.Any(cs => cs.CourseID == CourseID && cs.SubjectID == item.SubjectID))
                {
                    listSubjects.Add(new SelectListItem()
                    {
                        Text = item.Subject.Name, Value = item.SubjectID.ToString(), Selected = true
                    });
                }
                else
                {
                    listSubjects.Add(new SelectListItem()
                    {
                        Text = item.Subject.Name, Value = item.SubjectID.ToString(), Selected = false
                    });
                }
            }

            return(Json(listSubjects, JsonRequestBehavior.AllowGet));
        }
        public JsonResult AssignTo(int CourseID, int TeacherID)
        {
            CourseRepository courseRepository = new CourseRepository();
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();
            TeacherRepository teacherRepository = new TeacherRepository();
            Teacher teacher = new Teacher();
            teacher = teacherRepository.GetById(TeacherID);
            List<SelectListItem> listSubjects = new List<SelectListItem>();
            var allSubjects = courseSubjectRepo.GetAll(filter: s => s.CourseID == CourseID);

            foreach (var item in allSubjects)
            {
                if (teacher.CourseSubject.Any(cs => cs.CourseID == CourseID && cs.SubjectID == item.SubjectID))
                {
                    listSubjects.Add(new SelectListItem() { Text = item.Subject.Name, Value = item.SubjectID.ToString(), Selected = true });
                }
                else
                {
                    listSubjects.Add(new SelectListItem() { Text = item.Subject.Name, Value = item.SubjectID.ToString(), Selected = false });
                }

            }

            return Json(listSubjects, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 3
0
        public ActionResult EditCourseSubject(AdminControllerCourseSubjectVM courseSubjectModel)
        {
            CourseSubject           courseSubject           = new CourseSubject();
            CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();

            TryUpdateModel(courseSubjectModel);
            if (ModelState.IsValid && courseSubjectModel.CourseSubjectID > 0)
            {
                courseSubject.CourseID  = courseSubjectModel.courseID;
                courseSubject.SubjectID = courseSubjectModel.subjectID;
                courseSubjectRepository.Save(courseSubject);
                return(RedirectToAction("ShowSubjects", "Admin", new { @id = courseSubjectModel.courseID }));
            }
            if (courseSubjectModel.ListItems == null)
            {
                List <SelectListItem> List = new List <SelectListItem>();
                SubjectRepository     subjectRepository = new SubjectRepository();
                courseSubjectModel.subjectList = subjectRepository.GetAll();
                foreach (var item in courseSubjectModel.subjectList)
                {
                    List.Add(new SelectListItem()
                    {
                        Text = item.Name, Value = item.Id.ToString()
                    });
                }
                courseSubjectModel.ListItems = List;
            }
            return(View(courseSubjectModel));
        }
        public ActionResult Index()
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("Login", "Default"));
            }
            Student           student           = new Student();
            StudentRepository studentRepository = new StudentRepository();

            student = studentRepository.GetById(AuthenticationManager.LoggedUser.Id);
            StudentControllerStudentVM model  = new StudentControllerStudentVM();
            Course           course           = new Course();
            CourseRepository courseRepository = new CourseRepository();

            course = courseRepository.GetAll(filter: c => c.Id == student.CourseID).FirstOrDefault();
            List <Subject>          subjectList             = new List <Subject>();
            CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();

            subjectList = courseSubjectRepository.GetAll(filter: c => c.CourseID == course.Id).Select(s => s.Subject).ToList();
            List <string> subjectNames = new List <string>();

            foreach (var subject in subjectList)
            {
                subjectNames.Add(subject.Name);
            }
            model.Subjects       = subjectNames;
            model.FirstName      = student.FirstName;
            model.LastName       = student.LastName;
            model.StudentID      = AuthenticationManager.LoggedUser.Id;
            model.Course         = course.Name;
            model.FaculityNumber = student.FacultyNumber;
            return(View(model));
        }
 public ActionResult Index()
 {
     if (AuthenticationManager.LoggedUser == null)
     {
         return RedirectToAction("Login", "Default");
     }
     Student student = new Student();
     StudentRepository studentRepository = new StudentRepository();
     student = studentRepository.GetById(AuthenticationManager.LoggedUser.Id);
     StudentControllerStudentVM model = new StudentControllerStudentVM();
     Course course = new Course();
     CourseRepository courseRepository = new CourseRepository();
     course = courseRepository.GetAll(filter: c => c.Id == student.CourseID).FirstOrDefault();
     List<Subject> subjectList = new List<Subject>();
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     subjectList = courseSubjectRepository.GetAll(filter: c => c.CourseID == course.Id).Select(s => s.Subject).ToList();
     List<string> subjectNames = new List<string>();
     foreach (var subject in subjectList)
     {
         subjectNames.Add(subject.Name);
     }
     model.Subjects = subjectNames;
     model.FirstName = student.FirstName;
     model.LastName = student.LastName;
     model.StudentID = AuthenticationManager.LoggedUser.Id;
     model.Course = course.Name;
     model.FaculityNumber = student.FacultyNumber;
     return View(model);
 }
Exemplo n.º 6
0
        public ActionResult DeleteCourseSubject(int id, int courseId)
        {
            CourseSubject           courseSubject           = new CourseSubject();
            CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();

            courseSubject = courseSubjectRepository.GetAll(filter: s => s.SubjectID == id && s.Course.Id == courseId).FirstOrDefault();
            courseSubjectRepository.Delete(courseSubject);
            return(RedirectToAction("ShowSubjects", "Admin", new { @id = courseId }));
        }
Exemplo n.º 7
0
        public ActionResult ManageTeachers()
        {
            TeacherRepository        teacherRepository = new TeacherRepository();
            AdminControllerTeacherVM teacherModel      = new AdminControllerTeacherVM();
            List <CourseSubject>     courseSubject     = new List <CourseSubject>();
            CourseSubjectRepository  courseSubjectRepo = new CourseSubjectRepository();

            teacherModel.teacherList = teacherRepository.GetAll();

            return(View(teacherModel));
        }
        public ActionResult StudentDetails(int StudentID)
        {
            if (!AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                return(RedirectToAction("Default", "Login"));
            }
            List <Grade>      studentGrades     = new List <Grade>();
            GradeRepository   gradeRepository   = new GradeRepository();
            Student           student           = new Student();
            StudentRepository studentRepository = new StudentRepository();

            student = studentRepository.GetById(StudentID);
            TeacherControllerStudentsVM model = new TeacherControllerStudentsVM();

            studentGrades = gradeRepository.GetAll(filter: g => g.Student.Id == StudentID);

            model.FirstName      = student.FirstName;
            model.LastName       = student.LastName;
            model.FaculityNumber = student.FacultyNumber;
            model.Course         = student.Course.Name;
            model.StudentID      = student.Id;
            model.CourseID       = student.Course.Id;

            Dictionary <string, List <Grade> > details = new Dictionary <string, List <Grade> >();
            List <string> subjectNameList = new List <string>();

            foreach (var item in studentGrades)
            {
                subjectNameList.Add(item.Subject.Name);
            }
            subjectNameList = subjectNameList.Distinct().ToList();

            foreach (var item in subjectNameList)
            {
                List <Grade> grades = new List <Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == StudentID);
                details.Add(item, grades);
            }
            model.SubjectGradeList = details;

            List <Subject>          subjects          = new List <Subject>();
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();
            List <CourseSubject>    courseSubjectList = new List <CourseSubject>();

            courseSubjectList = courseSubjectRepo.GetAll(filter: c => c.CourseID == student.CourseID);
            foreach (var item in courseSubjectList)
            {
                subjects.Add(item.Subject);
            }
            model.SubjectList = subjects;
            return(View(model));
        }
Exemplo n.º 9
0
        public JsonResult CheckForAddedSubjects(int subjectId, int courseId)
        {
            bool                    isAdded           = false;
            CourseSubject           courseSubject     = new CourseSubject();
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();

            courseSubject = courseSubjectRepo.GetAll(filter: cs => cs.Course.Id == courseId && cs.Subject.Id == subjectId).FirstOrDefault();
            if (courseSubject != null)
            {
                isAdded = true;
            }
            return(Json(isAdded, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 10
0
        public ActionResult ShowCourseStudents(int id)
        {
            CourseSubjectRepository        courseSubjectRepository = new CourseSubjectRepository();
            AdminControllerCourseSubjectVM courseSubjectModel      = new AdminControllerCourseSubjectVM();
            StudentRepository studentRepository = new StudentRepository();
            List <Student>    studentList       = new List <Student>();

            courseSubjectModel.CourseSubjectID = id;
            if (id > 0)
            {
                courseSubjectModel.studentList = studentRepository.GetAll(filter: s => s.CourseID == id);
            }
            return(View(courseSubjectModel));
        }
Exemplo n.º 11
0
        public ActionResult ShowCourse(int id)
        {
            AdminControllerCourseSubjectVM courseSubjectModel      = new AdminControllerCourseSubjectVM();
            CourseSubjectRepository        courseSubjectRepository = new CourseSubjectRepository();

            courseSubjectModel.courseSubjectList = courseSubjectRepository.GetAll();
            List <Course> courseList = new List <Course>();

            courseSubjectModel.subjectID = id;
            foreach (var item in courseSubjectModel.courseSubjectList)
            {
                if (item.Subject.Id == id)
                {
                    courseList.Add(item.Course);
                }
            }
            courseSubjectModel.courseList = courseList;
            return(View(courseSubjectModel));
        }
Exemplo n.º 12
0
        public JsonResult DeleteSubject(int id)
        {
            bool subjectInUse = false;
            CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
            List <Course>           courseList = new List <Course>();

            courseList = courseSubjectRepository.GetAll(filter: cs => cs.Subject.Id == id).Select(c => c.Course).ToList();
            if (courseList.Count > 0)
            {
                subjectInUse = true;
            }
            else
            {
                SubjectRepository subjectRepository = new SubjectRepository();
                Subject           subject           = new Subject();
                subject = subjectRepository.GetById(id);
                subjectRepository.Delete(subject);
            }
            return(Json(subjectInUse, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Index()
        {
            if (AuthenticationManager.LoggedUser == null || !AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                return(RedirectToAction("Login", "Default"));
            }
            TeacherControllerTeacherVM model    = new TeacherControllerTeacherVM();
            Teacher           teacher           = new Teacher();
            TeacherRepository teacherRepository = new TeacherRepository();

            teacher         = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
            model.FirstName = teacher.FirstName;
            model.LastName  = teacher.LastName;
            CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
            CourseRepository        courseRepository        = new CourseRepository();
            SubjectRepository       subjectRepository       = new SubjectRepository();
            List <int> subjectList = new List <int>();
            Dictionary <string, List <Subject> > courseSubjectList = new Dictionary <string, List <Subject> >();
            List <Subject> subjects   = new List <Subject>();
            List <int>     courseList = new List <int>();

            foreach (var courseSubject in teacher.CourseSubject)
            {
                courseList.Add(courseSubject.Course.Id);
                subjectList.Add(courseSubject.Subject.Id);
            }
            subjectList = subjectList.Distinct().ToList();
            courseList  = courseList.Distinct().ToList();
            Course course = new Course();

            foreach (var courseID in courseList)
            {
                course   = courseRepository.GetById(courseID);
                subjects = courseSubjectRepository.GetAll(filter: c => c.Course.Id == courseID && subjectList.Contains(c.Subject.Id)).Select(s => s.Subject).ToList();
                courseSubjectList.Add(course.Name, subjects);
            }
            model.CourseSubjectList = courseSubjectList;
            return(View(model));
        }
Exemplo n.º 14
0
        public ActionResult EditCourseSubject(int courseID)
        {
            AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
            SubjectRepository       subjectRepository         = new SubjectRepository();
            CourseSubjectRepository courseSubjectRepo         = new CourseSubjectRepository();
            List <Subject>          subjectList = courseSubjectRepo.GetAll(filter: cs => cs.Course.Id == courseID).Select(s => s.Subject).ToList();

            courseSubjectModel.subjectList = subjectRepository.GetAll();//Except method is overriden
            List <SelectListItem> List = new List <SelectListItem>();

            foreach (var item in courseSubjectModel.subjectList)
            {
                List.Add(new SelectListItem()
                {
                    Text = item.Name, Value = item.Id.ToString()
                });
            }
            courseSubjectModel.ListItems       = List;
            courseSubjectModel.subjectList     = subjectRepository.GetAll();
            courseSubjectModel.courseID        = courseID;
            courseSubjectModel.CourseSubjectID = courseID;
            return(View(courseSubjectModel));
        }
Exemplo n.º 15
0
        public ActionResult AssignToCourse(AdminControllerTeacherVM model, string[] checkedSubjects)
        {
            UnitOfWork              unitOfWork        = new UnitOfWork();
            TeacherRepository       teacherRepository = new TeacherRepository(unitOfWork);
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository(unitOfWork);

            TryUpdateModel(model);
            Teacher teacher = teacherRepository.GetById(model.Id);

            CourseSubject courseSubject = null;

            try
            {
                List <CourseSubject> courseSubjectsList = courseSubjectRepo.GetAll(c => c.CourseID == model.CourseID && c.Teacher.Any(t => t.Id == model.Id));
                foreach (var item in courseSubjectsList)
                {
                    teacher.CourseSubject.Remove(item);
                }

                if (checkedSubjects != null)
                {
                    foreach (var item in checkedSubjects)
                    {
                        courseSubject = courseSubjectRepo.GetAll(filter: cs => cs.CourseID == model.CourseID && cs.SubjectID.ToString() == item).FirstOrDefault();
                        teacher.CourseSubject.Add(courseSubject);
                    }
                }
                teacherRepository.Save(teacher);
                unitOfWork.Commit();
            }
            catch (Exception)
            {
                unitOfWork.RollBack();
            }

            return(RedirectToAction("ManageTeachers", "Admin"));
        }
        public ActionResult AddSubject(int id, int[] subjectID, string Choose)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            CourseRepository courseRepo = new CourseRepository();
            CourseSubject cs = new CourseSubject();
            CourseSubjectRepository csRepo = new CourseSubjectRepository(unitOfWork);
            UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>(unitOfWork);
            Teacher teacher = teacherRepo.GetAll(filter: t => t.ID == id).FirstOrDefault();

            int courseId = Convert.ToInt32(Choose);

            var curSubj = csRepo.GetAll(filter: x => x.CourseID == courseId && x.Teachers.Any(t => t.ID == id));

            try
            {
                foreach (var item in curSubj)
                {
                    teacher.CourseSubject.Remove(item);
                }
                if (subjectID != null)
                {
                    foreach (var item in subjectID)
                    {
                        cs = csRepo.GetAll(filter: c => c.SubjectID == item && c.CourseID == courseId).FirstOrDefault();
                        teacher.CourseSubject.Add(cs);
                    }
                }
                teacherRepo.Save(teacher);
                unitOfWork.Commit();
            }
            catch (Exception)
            {
                unitOfWork.RollBack();
            }

            return RedirectToAction("ListTeachers", "Teacher");
        }
        public ActionResult AssignToCourse(AdminControllerTeacherVM model, string[] checkedSubjects)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            TeacherRepository teacherRepository = new TeacherRepository(unitOfWork);
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository(unitOfWork);
            TryUpdateModel(model);
            Teacher teacher = teacherRepository.GetById(model.Id);

            CourseSubject courseSubject = null;

            try
            {
                List<CourseSubject> courseSubjectsList = courseSubjectRepo.GetAll(c => c.CourseID == model.CourseID && c.Teacher.Any(t => t.Id == model.Id));
                foreach (var item in courseSubjectsList)
                {
                    teacher.CourseSubject.Remove(item);
                }

                if (checkedSubjects != null)
                {
                    foreach (var item in checkedSubjects)
                    {
                        courseSubject = courseSubjectRepo.GetAll(filter: cs => cs.CourseID == model.CourseID && cs.SubjectID.ToString() == item).FirstOrDefault();
                        teacher.CourseSubject.Add(courseSubject);
                    }
                }
                teacherRepository.Save(teacher);
                unitOfWork.Commit();
            }
            catch (Exception)
            {
                unitOfWork.RollBack();
            }

            return RedirectToAction("ManageTeachers", "Admin");
        }
Exemplo n.º 18
0
 public CourseSubjectService()
 {
     _courseSubjectRepository = new CourseSubjectRepository();
 }
 public ActionResult ShowCourse(int id)
 {
     AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     courseSubjectModel.courseSubjectList = courseSubjectRepository.GetAll();
     List<Course> courseList = new List<Course>();
     courseSubjectModel.subjectID = id;
     foreach (var item in courseSubjectModel.courseSubjectList)
     {
         if (item.Subject.Id == id)
         {
             courseList.Add(item.Course);
         }
     }
     courseSubjectModel.courseList = courseList;
     return View(courseSubjectModel);
 }
        public ActionResult ManageTeachers()
        {
            TeacherRepository teacherRepository = new TeacherRepository();
            AdminControllerTeacherVM teacherModel = new AdminControllerTeacherVM();
            List<CourseSubject> courseSubject = new List<CourseSubject>();
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();

            teacherModel.teacherList = teacherRepository.GetAll();

            return View(teacherModel);
        }
Exemplo n.º 21
0
        public ActionResult Articles()
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("Login", "Default"));
            }
            List <Article>    articleList              = new List <Article>();
            ArticleRepository articleRepository        = new ArticleRepository();
            Dictionary <int, List <Comment> > comments = new Dictionary <int, List <Comment> >();
            CommentRepository        commentRepository = new CommentRepository();
            Dictionary <int, string> userDictionary    = new Dictionary <int, string>();
            List <int>        subjectId         = new List <int>();
            Teacher           teacher           = new Teacher();
            TeacherRepository teacherRepository = new TeacherRepository();
            Student           student           = new Student();
            StudentRepository studentRepository = new StudentRepository();
            List <Article>    list = new List <Article>();

            if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
                foreach (var item in teacher.CourseSubject)
                {
                    subjectId.Add(item.Subject.Id);
                }
            }
            else if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Student)))
            {
                student = studentRepository.GetById(AuthenticationManager.LoggedUser.Id);
                List <CourseSubject>    courseSubjectList       = new List <CourseSubject>();
                CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
                courseSubjectList = courseSubjectRepository.GetAll(filter: cs => cs.CourseID == student.CourseID);
                foreach (var item in courseSubjectList)
                {
                    subjectId.Add(item.Subject.Id);
                }
            }
            subjectId = subjectId.Distinct().ToList();
            foreach (var item in subjectId)
            {
                List <Article> article = articleRepository.GetAll(filter: s => s.Subject.Id == item);
                if (article != null)
                {
                    articleList.AddRange(article);
                }
            }
            articleList = articleList.OrderBy(d => d.DateCreated.TimeOfDay).ToList();
            articleList.Reverse();
            ArticleControllerArticlesVM model              = new ArticleControllerArticlesVM();
            LikeRepository            likeRepository       = new LikeRepository();
            Dictionary <Article, int> ArticlesAndLikeCount = new Dictionary <Article, int>();
            Dictionary <int, bool>    Liked = new Dictionary <int, bool>();
            int    articleId = 0;
            string type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
            int    start     = type.LastIndexOf(".") + 1;
            int    positions = type.Length - start;

            type = type.Substring(start, positions);
            foreach (var item in articleList)
            {
                List <Comment> commentedCommentList = new List <Comment>();
                commentedCommentList = commentRepository.GetAll(filter: c => c.Article.Id == item.Id);
                commentedCommentList.OrderBy(c => c.DateCreated.TimeOfDay).ToList();
                commentedCommentList.Reverse();
                foreach (var comment in commentedCommentList)
                {
                    string userName = "";
                    if (comment.UserType == "Teacher")
                    {
                        teacher = teacherRepository.GetById(comment.UserID);
                        if (teacher != null)
                        {
                            userName = teacher.FirstName + " " + teacher.LastName;
                            userDictionary.Add(comment.Id, userName);
                        }
                    }
                    else
                    {
                        student  = studentRepository.GetById(comment.UserID);
                        userName = student.FirstName + " " + student.LastName;
                        userDictionary.Add(comment.Id, userName);
                    }
                }
                comments.Add(item.Id, commentedCommentList);
                int count = likeRepository.GetAll(filter: a => a.ArticleID == item.Id).Count;
                ArticlesAndLikeCount.Add(item, count);
                List <Like> likes = new List <Like>();

                likes = likeRepository.GetAll(l => l.ArticleID == item.Id);
                foreach (var like in likes.Where(l => l.UserID == AuthenticationManager.LoggedUser.Id && l.UserType == type))
                {
                    Liked.Add(item.Id, true);
                }
                model.ArticleId = item.Id;
                if (Liked.Count != ArticlesAndLikeCount.Count)
                {
                    foreach (var dictionary in ArticlesAndLikeCount.Where(a => a.Key.Id == item.Id))
                    {
                        articleId = item.Id;
                    }
                    Liked.Add(articleId, false);
                }
            }
            model.UserType       = type;
            model.IsLiked        = Liked;
            model.UserID         = AuthenticationManager.LoggedUser.Id;
            model.Articles       = ArticlesAndLikeCount;
            model.CommentList    = comments;
            model.UserDictionary = userDictionary;
            return(View(model));
        }
        public ActionResult EditCourseSubject(int courseID)
        {
            AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
            SubjectRepository subjectRepository = new SubjectRepository();
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();
            List<Subject> subjectList = courseSubjectRepo.GetAll(filter: cs => cs.Course.Id == courseID).Select(s => s.Subject).ToList();
            courseSubjectModel.subjectList = subjectRepository.GetAll();//Except method is overriden
            List<SelectListItem> List = new List<SelectListItem>();

            foreach (var item in courseSubjectModel.subjectList)
            {
                List.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() });
            }
            courseSubjectModel.ListItems = List;
            courseSubjectModel.subjectList = subjectRepository.GetAll();
            courseSubjectModel.courseID = courseID;
            courseSubjectModel.CourseSubjectID = courseID;
            return View(courseSubjectModel);
        }
 public JsonResult DeleteSubject(int id)
 {
     bool subjectInUse = false;
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     List<Course> courseList = new List<Course>();
     courseList = courseSubjectRepository.GetAll(filter: cs => cs.Subject.Id == id).Select(c => c.Course).ToList();
     if (courseList.Count > 0)
     {
         subjectInUse = true;
     }
     else
     {
         SubjectRepository subjectRepository = new SubjectRepository();
         Subject subject = new Subject();
         subject = subjectRepository.GetById(id);
         subjectRepository.Delete(subject);
     }
     return Json(subjectInUse, JsonRequestBehavior.AllowGet);
 }
 public ActionResult DeleteCourseSubject(int id, int courseId)
 {
     CourseSubject courseSubject = new CourseSubject();
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     courseSubject = courseSubjectRepository.GetAll(filter: s => s.SubjectID == id && s.Course.Id == courseId).FirstOrDefault();
     courseSubjectRepository.Delete(courseSubject);
     return RedirectToAction("ShowSubjects", "Admin", new { @id = courseId });
 }
        public ActionResult Articles()
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return RedirectToAction("Login", "Default");
            }
            List<Article> articleList = new List<Article>();
            ArticleRepository articleRepository = new ArticleRepository();
            Dictionary<int, List<Comment>> comments = new Dictionary<int, List<Comment>>();
            CommentRepository commentRepository = new CommentRepository();
            Dictionary<int, string> userDictionary = new Dictionary<int, string>();
            List<int> subjectId = new List<int>();
            Teacher teacher = new Teacher();
            TeacherRepository teacherRepository = new TeacherRepository();
            Student student = new Student();
            StudentRepository studentRepository = new StudentRepository();
            List<Article> list = new List<Article>();
            if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
                foreach (var item in teacher.CourseSubject)
                {
                    subjectId.Add(item.Subject.Id);
                }
            }
            else if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Student)))
            {
                student = studentRepository.GetById(AuthenticationManager.LoggedUser.Id);
                List<CourseSubject> courseSubjectList = new List<CourseSubject>();
                CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
                courseSubjectList = courseSubjectRepository.GetAll(filter: cs => cs.CourseID == student.CourseID);
                foreach (var item in courseSubjectList)
                {
                    subjectId.Add(item.Subject.Id);
                }
            }
            subjectId = subjectId.Distinct().ToList();
            foreach (var item in subjectId)
            {
                List<Article> article = articleRepository.GetAll(filter: s => s.Subject.Id == item);
                if (article != null)
                {
                    articleList.AddRange(article);
                }
            }
            articleList = articleList.OrderBy(d => d.DateCreated.TimeOfDay).ToList();
            articleList.Reverse();
            ArticleControllerArticlesVM model = new ArticleControllerArticlesVM();
            LikeRepository likeRepository = new LikeRepository();
            Dictionary<Article, int> ArticlesAndLikeCount = new Dictionary<Article, int>();
            Dictionary<int, bool> Liked = new Dictionary<int, bool>();
            int articleId = 0;
            string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
            int start = type.LastIndexOf(".") + 1;
            int positions = type.Length - start;
            type = type.Substring(start, positions);
            foreach (var item in articleList)
            {
                List<Comment> commentedCommentList = new List<Comment>();
                commentedCommentList = commentRepository.GetAll(filter: c => c.Article.Id == item.Id);
                commentedCommentList.OrderBy(c => c.DateCreated.TimeOfDay).ToList();
                commentedCommentList.Reverse();
                foreach (var comment in commentedCommentList)
                {
                    string userName = "";
                    if (comment.UserType == "Teacher")
                    {
                        teacher = teacherRepository.GetById(comment.UserID);
                        if (teacher != null)
                        {
                            userName = teacher.FirstName + " " + teacher.LastName;
                            userDictionary.Add(comment.Id, userName);
                        }
                    }
                    else
                    {
                        student = studentRepository.GetById(comment.UserID);
                        userName = student.FirstName + " " + student.LastName;
                        userDictionary.Add(comment.Id, userName);
                    }
                }
                comments.Add(item.Id, commentedCommentList);
                int count = likeRepository.GetAll(filter: a => a.ArticleID == item.Id).Count;
                ArticlesAndLikeCount.Add(item, count);
                List<Like> likes = new List<Like>();

                likes = likeRepository.GetAll(l => l.ArticleID == item.Id);
                foreach (var like in likes.Where(l => l.UserID == AuthenticationManager.LoggedUser.Id && l.UserType == type))
                {
                    Liked.Add(item.Id, true);
                }
                model.ArticleId = item.Id;
                if (Liked.Count != ArticlesAndLikeCount.Count)
                {
                    foreach (var dictionary in ArticlesAndLikeCount.Where(a => a.Key.Id == item.Id))
                    {
                        articleId = item.Id;
                    }
                    Liked.Add(articleId, false);
                }
            }
            model.UserType = type;
            model.IsLiked = Liked;
            model.UserID = AuthenticationManager.LoggedUser.Id;
            model.Articles = ArticlesAndLikeCount;
            model.CommentList = comments;
            model.UserDictionary = userDictionary;
            return View(model);
        }
 public ActionResult ShowCourseStudents(int id)
 {
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     AdminControllerCourseSubjectVM courseSubjectModel = new AdminControllerCourseSubjectVM();
     StudentRepository studentRepository = new StudentRepository();
     List<Student> studentList = new List<Student>();
     courseSubjectModel.CourseSubjectID = id;
     if (id > 0)
     {
         courseSubjectModel.studentList = studentRepository.GetAll(filter: s => s.CourseID == id);
     }
     return View(courseSubjectModel);
 }
        public ActionResult Index()
        {
            TeacherIndexVM model = new TeacherIndexVM();
            CourseRepository courseRepo = new CourseRepository();

            SubjectRepository subjRepo = new SubjectRepository();

            CourseSubjectRepository csRepo = new CourseSubjectRepository();

            model.Subjects = subjRepo.GetAll(filter: s => s.CourseSubject.Any(c => c.Teachers.Any(t => t.ID == UniversitySystem.Models.AuthenticationManager.LoggedUser.ID)));

            model.Courses = courseRepo.GetAll(filter: c => c.CourseSubject.Any(s => s.Teachers.Any(t => t.ID == UniversitySystem.Models.AuthenticationManager.LoggedUser.ID)));

            return View(model);
        }
 public ActionResult Index()
 {
     if (AuthenticationManager.LoggedUser == null || !AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
     {
         return RedirectToAction("Login", "Default");
     }
     TeacherControllerTeacherVM model = new TeacherControllerTeacherVM();
     Teacher teacher = new Teacher();
     TeacherRepository teacherRepository = new TeacherRepository();
     teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
     model.FirstName = teacher.FirstName;
     model.LastName = teacher.LastName;
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     CourseRepository courseRepository = new CourseRepository();
     SubjectRepository subjectRepository = new SubjectRepository();
     List<int> subjectList = new List<int>();
     Dictionary<string, List<Subject>> courseSubjectList = new Dictionary<string, List<Subject>>();
     List<Subject> subjects = new List<Subject>();
     List<int> courseList = new List<int>();
     foreach (var courseSubject in teacher.CourseSubject)
     {
         courseList.Add(courseSubject.Course.Id);
         subjectList.Add(courseSubject.Subject.Id);
     }
     subjectList = subjectList.Distinct().ToList();
     courseList = courseList.Distinct().ToList();
     Course course = new Course();
     foreach (var courseID in courseList)
     {
         course = courseRepository.GetById(courseID);
         subjects = courseSubjectRepository.GetAll(filter: c => c.Course.Id == courseID && subjectList.Contains(c.Subject.Id)).Select(s => s.Subject).ToList();
         courseSubjectList.Add(course.Name, subjects);
     }
     model.CourseSubjectList = courseSubjectList;
     return View(model);
 }
        public ActionResult StudentDetails(int StudentID)
        {
            if (!AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                return RedirectToAction("Default", "Login");
            }
            List<Grade> studentGrades = new List<Grade>();
            GradeRepository gradeRepository = new GradeRepository();
            Student student = new Student();
            StudentRepository studentRepository = new StudentRepository();
            student = studentRepository.GetById(StudentID);
            TeacherControllerStudentsVM model = new TeacherControllerStudentsVM();
            studentGrades = gradeRepository.GetAll(filter: g => g.Student.Id == StudentID);

            model.FirstName = student.FirstName;
            model.LastName = student.LastName;
            model.FaculityNumber = student.FacultyNumber;
            model.Course = student.Course.Name;
            model.StudentID = student.Id;
            model.CourseID = student.Course.Id;

            Dictionary<string, List<Grade>> details = new Dictionary<string, List<Grade>>();
            List<string> subjectNameList = new List<string>();

            foreach (var item in studentGrades)
            {
                subjectNameList.Add(item.Subject.Name);
            }
            subjectNameList = subjectNameList.Distinct().ToList();

            foreach (var item in subjectNameList)
            {
                List<Grade> grades = new List<Grade>();
                grades = gradeRepository.GetAll(filter: s => s.Subject.Name == item && s.Student.Id == StudentID);
                details.Add(item, grades);
            }
            model.SubjectGradeList = details;

            List<Subject> subjects = new List<Subject>();
            CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();
            List<CourseSubject> courseSubjectList = new List<CourseSubject>();
            courseSubjectList = courseSubjectRepo.GetAll(filter: c => c.CourseID == student.CourseID);
            foreach (var item in courseSubjectList)
            {
                subjects.Add(item.Subject);
            }
            model.SubjectList = subjects;
            return View(model);
        }
 public ActionResult EditSubjectCourse(AdminControllerCourseSubjectVM subjectCourseModel)
 {
     CourseSubject courseSubject = new CourseSubject();
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     TryUpdateModel(subjectCourseModel);
     if (ModelState.IsValid && subjectCourseModel.CourseSubjectID > 0)
     {
         courseSubject.CourseID = subjectCourseModel.courseID;
         courseSubject.SubjectID = subjectCourseModel.subjectID;
         courseSubjectRepository.Save(courseSubject);
         return RedirectToAction("ShowCourse", "Admin", new { @id = subjectCourseModel.subjectID });
     }
     if (subjectCourseModel.ListItems == null)
     {
         List<SelectListItem> List = new List<SelectListItem>();
         CourseRepository courseRepository = new CourseRepository();
         subjectCourseModel.courseList = courseRepository.GetAll();
         foreach (var item in subjectCourseModel.courseList)
         {
             List.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() });
         }
         subjectCourseModel.ListItems = List;
     }
     return View(subjectCourseModel);
 }
 public JsonResult CheckForAddedSubjects(int subjectId, int courseId)
 {
     bool isAdded = false;
     CourseSubject courseSubject = new CourseSubject();
     CourseSubjectRepository courseSubjectRepo = new CourseSubjectRepository();
     courseSubject = courseSubjectRepo.GetAll(filter: cs => cs.Course.Id == courseId && cs.Subject.Id == subjectId).FirstOrDefault();
     if (courseSubject != null)
     {
         isAdded = true;
     }
     return Json(isAdded, JsonRequestBehavior.AllowGet);
 }
        public JsonResult States(string Choose, int teacherID)
        {
            CourseRepository cRepo = new CourseRepository();
            CourseSubjectRepository csRepo = new CourseSubjectRepository();

            List<SelectListItem> StatesList = new List<SelectListItem>();

            int choose = Convert.ToInt32(Choose);

            var subjects = csRepo.GetAll(filter: s => s.CourseID == choose);

            foreach (var item in subjects)
            {
                if (item.Teachers.Any(x => x.ID == teacherID))
                {
                    StatesList.Add(new SelectListItem() { Text = item.Subject.Name, Value = item.SubjectID.ToString(), Selected = true });
                }
                else
                {
                    StatesList.Add(new SelectListItem() { Text = item.Subject.Name, Value = item.SubjectID.ToString(), Selected = false });
                }
            }

            return Json(StatesList, JsonRequestBehavior.AllowGet);
        }