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");
        }
        /// <summary>
        /// This method is called to add or remove Keyword from article
        /// </summary>
        public void AddRemoveKeywords(string keywords, int infoID)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            KeywordsRepository keywordsRepository = new KeywordsRepository(unitOfWork);
            InfoRepository infoRepository = new InfoRepository(unitOfWork);

            Info info = infoRepository.GetByID(infoID);

            List<int> KeywordsIDList = new List<int>();
            if (keywords != null)
            {
                string[] keywordsArray = keywords.Split(',');

                foreach (var keywordInput in keywordsArray)
                {
                    string value = keywordInput.Trim();
                    value = Regex.Replace(value, @"\s+", " ");

                    Keyword keyword = keywordsRepository.GetAll(filter: x => x.Value == value).FirstOrDefault();

                    if (keyword == null)
                    {
                        if (value != string.Empty)
                        {
                            keyword = new Keyword();
                            keyword.Value = value;
                            keywordsRepository.Save(keyword);

                            KeywordsIDList.Add(keyword.ID);
                        }
                    }
                    else
                    {
                        KeywordsIDList.Add(keyword.ID);
                    }
                }
            }

            List<int> currentArticleKeywordsID = new List<int>();
            info.Keywords = info.Keywords == null ? info.Keywords = new List<Keyword>() : info.Keywords;

            try
            {
                foreach (var item in info.Keywords)
                {
                    currentArticleKeywordsID.Add(item.ID);
                }

                IEnumerable<int> removedKeywordsID = currentArticleKeywordsID.Except(KeywordsIDList);

                foreach (Keyword keyword in info.Keywords.ToList().Where(x => removedKeywordsID.Any(k => k == x.ID)))
                {
                    keyword.Info.Remove(info);
                    keywordsRepository.Save(keyword);
                }

                IEnumerable<int> addKeywordToArticle = KeywordsIDList.Except(currentArticleKeywordsID);

                foreach (var keyID in addKeywordToArticle)
                {
                    Keyword keyword = keywordsRepository.GetByID(keyID);
                    keyword.Info = keyword.Info == null ? new List<Info>() : keyword.Info;
                    keyword.Info.Add(info);

                    keywordsRepository.Save(keyword);
                }
                unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                unitOfWork.RollBack();
                throw ex;
            }
        }
        public ActionResult CreateTeacher(TeacherCreateTeacherVM model)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            Teacher teacher = new Teacher();
            UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>(unitOfWork);
            TitleRepository titleRepo = new TitleRepository(unitOfWork);

            if (!ModelState.IsValid)
            {
                model.TitleList = TeacherTitle();

                return View(model);
            }

            try
            {
                teacher.Username = model.FirstName;
                teacher.FirstName = model.FirstName;
                teacher.LastName = model.LastName;

                int tittleId = Convert.ToInt32(model.selectedValueID);

                Title title = titleRepo.GetByID(tittleId);

                teacher.Title = title;

                UniversitySystem.Hasher.Passphrase hash = UniversitySystem.Hasher.PasswordHasher.Hash("password");
                teacher.Hash = hash.Hash;
                teacher.Salt = hash.Salt;
                teacher.Active = true;

                teacherRepo.Save(teacher);

                unitOfWork.Commit();
            }

            catch (Exception)
            {
                unitOfWork.RollBack();
                throw;
            }

            return RedirectToAction("ListTeachers", "Teacher");
        }
        public ActionResult EditTeacher(TeacherEditTeacherVM model)
        {
            if (!ModelState.IsValid)
            {
                model.TitleList = TeacherTitle();
                return View(model);
            }
            UnitOfWork unitOfWork = new UnitOfWork();
            UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>(unitOfWork);
            TitleRepository tiRepo = new TitleRepository(unitOfWork);

            Teacher teacher = teacherRepo.GetByID(model.TeacherID);

            try
            {
                int TitleId = Convert.ToInt32(model.selectedValueID);
                Title title = tiRepo.GetByID(TitleId);

                if (model.FirstName != teacher.FirstName || model.LastName != teacher.LastName || model.Active != teacher.Active || TitleId != teacher.Title.ID)
                {
                    teacher.FirstName = model.FirstName;
                    teacher.LastName = model.LastName;
                    teacher.Username = model.FirstName;
                    teacher.Active = model.Active;
                    teacher.Title = title;

                    teacherRepo.Save(teacher);
                    unitOfWork.Commit();
                }
            }
            catch (Exception)
            {
                unitOfWork.RollBack();
            }
            return RedirectToAction("ListTeachers", "Teacher");
        }