public ActionResult Edit([Bind(Include = "Id,CodeTest,Title,Note,NumberOfQuestions,Time,ExamID,ScoreLadderID,Status")] Test test) { var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; if (CheckInputTest(test)) { if (ModelState.IsValid) { if (SelectQuiz(test)) { SetAlert("Cập nhật đề thi thành công", "success"); new SystemLogDAO().Insert("Cập nhật đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + test.Exam.Titile + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(RedirectToAction("Index")); } else { SetAlert("Cập nhật đề thi không thành công", "error"); return(RedirectToAction("Index")); } } } SetExamViewBag(test.ExamID); SetExamineeViewBag(); //SetSchoolYearViewBag(test.Subject.Grade.SchoolYearID); //SetGradeViewBag(test.Subject.GradeID); //SetSubjectViewBag(test.SubjectID); //SetScoreLadderViewBag(test.ScoreLadderID); return(View()); }
// Chọn câu hỏi private bool SelectQuiz(Test test) { var _exam = new ExamDAO().GetExamById(test.ExamID); // Chọn câu hỏi theo kiểu ngẫu nhiên (random) if (test.QuizSelection == ConstantVariable.RandomQuiz) { //Lấy tất cả câu hỏi theo môn học từ kỳ thi đã chọn var _quizList = new QuizDAO().GetAllQuizBySubject(_exam.SubjectID); var _codeTestArr = Regex.Split(test.CodeTestArr, ","); //Trả về mảng mã đề var _session = Session[ConstantVariable.USER_SESSION] as UserLogin; // Thông tin user đăng nhập //Hình thức: không cố định câu hỏi / khác nhau ở mỗi đề if (test.FixedOrChanged == ConstantVariable.ChangedQuiz) { //Kiểm tra số câu hỏi có đủ hay không if ((test.NumberOfQuestions * _codeTestArr.Length) > _quizList.Count) { ModelState.AddModelError("", "Số câu hỏi trong ngân hàng câu hỏi không đủ để tạo đề thi này."); return(false); } List <int> _quizIdList = new List <int>(); for (int i = 0; i < _codeTestArr.Length; i++) { if (!String.IsNullOrEmpty(_codeTestArr[i])) { test.CodeTest = int.Parse(_codeTestArr[i]); //Mã đề Random random = new Random(); List <int> _quizIdListByCodeTest = new List <int>(); for (int j = 0; j < test.NumberOfQuestions; j++) { int quizId; do { quizId = _quizList[random.Next(0, _quizList.Count - 1)].Id; } while (_quizIdList.Contains(quizId)); _quizIdListByCodeTest.Add(quizId); } test.CreatedBy = _session.UserID; //Người tạo test.CreatedDate = DateTime.Now; test.ModifiedDate = DateTime.Now; var r = new TestDAO().Insert(test, _quizIdListByCodeTest); if (r == false) { return(r); } new SystemLogDAO().Insert("Tạo đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + _exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); } }//end:For } // Hình thức: cố định câu hỏi else if (test.FixedOrChanged == ConstantVariable.FixedQuiz) { // Kiểm tra số câu hỏi có đủ hay không if (test.NumberOfQuestions > _quizList.Count) { ModelState.AddModelError("", "Số câu hỏi trong ngân hàng câu hỏi không đủ để tạo đề thi này."); return(false); } // Trộn câu hỏi if (test.Mix == ConstantVariable.MixQuiz) { List <int> _quizIdList = new List <int>(); List <int> _quizIdList0 = new List <int>(); bool r = false; for (int i = 0; i < _codeTestArr.Length; i++) { if (!String.IsNullOrEmpty(_codeTestArr[i])) { test.CodeTest = int.Parse(_codeTestArr[i]); //Mã đề Random random = new Random(); if (i == 0) { for (int j = 0; j < test.NumberOfQuestions; j++) { int quizId; do { quizId = _quizList[random.Next(0, _quizList.Count - 1)].Id; } while (_quizIdList.Contains(quizId)); _quizIdList.Add(quizId); var _quiz = new QuizDAO().GetById(quizId); _quiz.MixQuiz += "<" + test.CodeTest + ">" + j + "</" + test.CodeTest + ">"; new QuizDAO().UpdateMixQuiz(_quiz); } test.CreatedBy = _session.UserID; //Người tạo test.CreatedDate = DateTime.Now; test.ModifiedDate = DateTime.Now; r = new TestDAO().Insert(test, _quizIdList); if (r == false) { return(r); } _quizIdList0 = _quizIdList.ToList(); new SystemLogDAO().Insert("Tạo đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + _exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); } else { List <int> _quizIdListMixQuiz = new List <int>(); List <int> _temp = _quizIdList0.ToList(); for (int j = 0; j < test.NumberOfQuestions; j++) { int quizId; int index; do { index = random.Next(0, _temp.Count - 1); quizId = _temp[index]; } while (_quizIdListMixQuiz.Contains(quizId)); _quizIdListMixQuiz.Add(quizId); _temp.RemoveAt(index); if (j == test.NumberOfQuestions - 1) { int _count = 0; for (int k = 0; k < test.NumberOfQuestions; k++) { if (_quizIdListMixQuiz[k] == _quizIdList0[k]) { _count++; } } if (_count >= test.NumberOfQuestions) { j = -1; _temp.Clear(); _temp = _quizIdListMixQuiz.ToList(); _quizIdListMixQuiz.Clear(); } } } for (int p = 0; p < _quizIdListMixQuiz.Count; p++) { var _quiz = new QuizDAO().GetById(_quizIdListMixQuiz[p]); _quiz.MixQuiz += "<" + test.CodeTest + ">" + p + "</" + test.CodeTest + ">"; new QuizDAO().UpdateMixQuiz(_quiz); } test.CreatedBy = _session.UserID; //Người tạo test.CreatedDate = DateTime.Now; test.ModifiedDate = DateTime.Now; r = new TestDAO().Insert(test, _quizIdListMixQuiz); if (r == false) { return(r); } test.MixQuiz = true; new TestDAO().UpdateMixQuiz(test); new SystemLogDAO().Insert("Tạo đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + _exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); } } } //end:For } //end-if: trộn câu hỏi //Trộn đáp án else if (test.Mix == ConstantVariable.MixAnswer) { char[] Alphabet = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' }; List <int> _quizIdList = new List <int>(); List <int> _quizIdList0 = new List <int>(); bool r = false; for (int i = 0; i < _codeTestArr.Length; i++) { if (!String.IsNullOrEmpty(_codeTestArr[i])) { test.CodeTest = int.Parse(_codeTestArr[i]); //Mã đề Random random = new Random(); if (i == 0) { for (int j = 0; j < test.NumberOfQuestions; j++) { int quizId; do { quizId = _quizList[random.Next(0, _quizList.Count - 1)].Id; } while (_quizIdList.Contains(quizId)); _quizIdList.Add(quizId); var _quiz = new QuizDAO().GetById(quizId); _quiz.MixAnswer += "<" + test.CodeTest + ">" + _quiz.AnswerText + "</" + test.CodeTest + ">"; _quiz.MixKeyAnswer += "<" + test.CodeTest + ">" + _quiz.KeyAnswer + "</" + test.CodeTest + ">"; new QuizDAO().UpdateMixAnswer(_quiz); } test.CreatedBy = _session.UserID; //Người tạo test.CreatedDate = DateTime.Now; test.ModifiedDate = DateTime.Now; r = new TestDAO().Insert(test, _quizIdList); if (r == false) { return(r); } _quizIdList0 = _quizIdList; new SystemLogDAO().Insert("Tạo đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + _exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); } else //Mix: Answer { List <int> _temp = _quizIdList0; for (int j = 0; j < _temp.Count; j++) { var _quiz = new QuizDAO().GetById(_temp[j]); var _answer = Regex.Split(_quiz.AnswerText, "\r\n").ToList(); List <string> _answerArr = new List <string>(); int alpha = 0; // Remove các giá trị null hoặc "" for (int k = 0; k < _answer.Count; k++) { if (!String.IsNullOrEmpty(_answer[k])) { var strPattern = "" + Alphabet[alpha] + ". "; _answerArr.Add(Encode.StripAnswerLabel(Encode.StripPTag(_answer[k]), strPattern)); alpha++; } } _quiz.MixAnswer += "<" + test.CodeTest + ">"; int _numChoice = _answerArr.Count; int indexKey = 0; // Lấy index của đáp án for (int p = 0; p < Alphabet.Length; p++) { if (Alphabet[p].ToString() == _quiz.KeyAnswer.ToString()) { indexKey = p; break; } } // Trộn đáp án của câu hỏi for (int k = 0; k < _numChoice; k++) { var indexRandom = random.Next(0, _answerArr.Count - 1); if (!String.IsNullOrEmpty(_answerArr[indexRandom])) { _quiz.MixAnswer += "<p>" + Alphabet[k] + ". " + Encode.StripPTag(_answerArr[indexRandom]) + "\r\n</p>"; if (indexKey != -1) { if (indexRandom < indexKey) { indexKey--; } else if (indexRandom == indexKey) { _quiz.MixKeyAnswer += "<" + test.CodeTest + ">" + Alphabet[k].ToString() + "</" + test.CodeTest + ">"; indexKey = -1; } } _answerArr.RemoveAt(indexRandom); } } _quiz.MixAnswer += "</" + test.CodeTest + ">"; test.MixAnswer = true; new QuizDAO().UpdateMixAnswer(_quiz); new TestDAO().UpdateMixAnswer(test); }//end-for test.CreatedBy = _session.UserID; //Người tạo test.CreatedDate = DateTime.Now; test.ModifiedDate = DateTime.Now; r = new TestDAO().Insert(test, _temp); if (r == false) { return(r); } new SystemLogDAO().Insert("Tạo đề thi thành công [Mã đề: " + test.CodeTest + "] [Kỳ thi: " + _exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); } } } } // Trộn câu hỏi và đáp án else if (test.Mix == ConstantVariable.MixAll) { // Trộn câu hỏi List <int> _quizIdList = new List <int>(); //Chứa câu hỏi của đề đầu tiên List <int> _quizIdList0 = new List <int>(); //Chứa câu hỏi của các đề tiếp theo bool r = false; for (int i = 0; i < _codeTestArr.Length; i++) { if (!String.IsNullOrEmpty(_codeTestArr[i])) { test.CodeTest = int.Parse(_codeTestArr[i]); //Mã đề Random random = new Random(); if (i == 0) { for (int j = 0; j < test.NumberOfQuestions; j++) { int quizId; do { quizId = _quizList[random.Next(0, _quizList.Count - 1)].Id; } while (_quizIdList.Contains(quizId)); _quizIdList.Add(quizId); } _quizIdList0 = _quizIdList; }//end-if (i == 0) else { List <int> _quizIdListMixQuiz = new List <int>(); List <int> _temp = _quizIdList0; for (int j = 0; j < test.NumberOfQuestions; j++) { int quizId; int index; do { index = random.Next(0, _temp.Count - 1); quizId = _temp[index]; } while (_quizIdListMixQuiz.Contains(quizId)); _quizIdListMixQuiz.Add(quizId); _temp.RemoveAt(index); if (j == test.NumberOfQuestions - 1) { int _count = 0; for (int k = 0; k < test.NumberOfQuestions; k++) { if (_quizIdListMixQuiz[k] == _quizIdList0[k]) { _count++; } } if (_count >= test.NumberOfQuestions) { j = 0; _temp = null; _temp = _quizIdListMixQuiz; _quizIdListMixQuiz = null; } } } } //end-else of if (i == 0) } //end-if (!String.IsNullOrEmpty(_codeTestArr[i])) } //end-for // Trộn đáp án // Insert dữ liệu } //end-if (test.Mix == ConstantVariable.MixAll) } //end-if (test.FixedOrChanged == ConstantVariable.FixedQuiz) } // Chọn câu hỏi theo kiểu câu hỏi mới nhất if (test.QuizSelection == ConstantVariable.NewQuiz) { var _quizList = new QuizDAO().GetAllQuizNewSubject(_exam.SubjectID); if (_quizList.Count < test.NumberOfQuestions) { ModelState.AddModelError("", "Số câu hỏi trong ngân hàng câu hỏi không đủ để tạo đề thi này."); return(false); } else { List <int> _quizIdList = new List <int>(); for (int i = 0; i < test.NumberOfQuestions; i++) { _quizIdList.Add(_quizList[i].Id); } var _session = Session[ConstantVariable.USER_SESSION] as UserLogin; test.CreatedBy = _session.UserID; test.CreatedDate = DateTime.Now; test.ModifiedDate = DateTime.Now; return(new TestDAO().Insert(test, _quizIdList)); } } return(true); }
public ActionResult DeleteConfirmed(int id) { var _quizDao = new QuizDAO(); var _quiz = _quizDao.GetById(id); var _session = Session[ConstantVariable.USER_SESSION] as UserLogin; if (_session != null) { if (_quiz.UserID == _session.UserID) { var _result = _quizDao.Delete(_quiz); if (_result) { SetAlert("Xóa câu hỏi thành công", "success"); new SystemLogDAO().Insert("Xóa câu hỏi thành công [ID = " + _quiz.Id + "] [ID môn học: " + _quiz.SubjectsID + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/quiz")); } else { SetAlert("Xóa câu hỏi không thành công | Lỗi: Câu hỏi này đã được dùng trong đề thi.", "warning"); return(Redirect("/admin/quiz")); } } else { SetAlert("Xóa câu hỏi không thành công | Lỗi: Bạn không có quyền xóa câu hỏi này", "warning"); return(Redirect("/admin/quiz")); } } return(RedirectToAction("Index")); }
public ActionResult Create(Question question) { var _quizDao = new QuizDAO(); var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; if (CheckInputQuiz(question)) { if (ModelState.IsValid) { var _session = Session["USER_SESSION"] as UserLogin; if (_session != null) { question.UserID = _session.UserID; } // Nội dung câu hỏi if (!String.IsNullOrEmpty(question.ContentQuestion)) { question.ContentQuestionEncode = WebUtility.HtmlDecode(Encode.StripHTML(question.ContentQuestion)); } if (!String.IsNullOrEmpty(question.AnswerText)) { question.AnswerTextEncode = WebUtility.HtmlDecode(Encode.StripHTML(question.AnswerText)); } question.DateCreated = DateTime.Now; //Ngày tạo question.ModifiedDate = question.DateCreated; // Ngày chỉnh sửa var r = _quizDao.Insert(question); // Gọi phương thức để tạo câu hỏi if (r > 0) { new SystemLogDAO().Insert("Tạo câu hỏi thành công [ID = " + question.Id + "] [ID môn học: " + question.SubjectsID + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); SetAlert("Tạo câu hỏi thành công.", "success"); return(RedirectToAction("Index", "quiz")); } else { SetAlert("Chỉnh sửa câu hỏi không thành công.", "error"); return(Redirect("/admin/quiz")); } } } SetSchoolYearViewBag(); SetGradeViewBag(question); SetCategoryViewBag(question.CategoryID); SetKindViewBag(question.KindID); SetLevelViewBag(question.LevelID); SetAnswerChoiceNumViewBag(question.AnswerChoiceNum); SetSubjectViewBag(question.SubjectsID); return(View()); }
public ActionResult login(AdminLoginModel model) { //Form Không rỗng if (ModelState.IsValid) { var _userDao = new UserDAO(); var _result = _userDao.Login(model.UserName, Encode.MD5Hash(model.PassWord)); if (_result == 1) { var _user = _userDao.GetUserByUserName(model.UserName); var _userSession = new UserLogin(); _userSession.UserName = _user.UserName; _userSession.UserID = _user.Id; _userSession.GroupID = _user.GroupID; var _listRole = _userDao.GetListRole(model.UserName); if (_user.Avatar != null) { _userSession.Avatar = _user.Avatar; } else { _userSession.Avatar = "/Data/images/avatardefault.png"; } Session.Add(ConstantVariable.USER_SESSION, _userSession); Session.Add(ConstantVariable.SESSION_CREDENTIAL, _listRole); new SystemLogDAO().Insert("Người dùng [" + _user.UserName + "] đăng nhập thành công", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(RedirectToAction("Index", "home")); } else if (_result == ConstantVariable.NotExist) // 0 { ModelState.AddModelError("", "Tài khoản không tồn tại!"); } else if (_result == ConstantVariable.IsLocked) // -1 { ModelState.AddModelError("", "Tài khoản đang bị khóa!"); } else if (_result == ConstantVariable.Incorrect) // -2 { ModelState.AddModelError("", "Tài khoản hoặc mật khẩu chưa đúng!"); } else if (_result == ConstantVariable.NotHaveAccess) // -3 { ModelState.AddModelError("", "Tài khoản của bạn không có quyền truy cập!"); } else { ModelState.AddModelError("", "Có lỗi! Đăng nhập không thành công!"); } } return(View("Index")); }
public ActionResult Delete(int?id) { var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var _user = new UserDAO().GetUserById(id); if (_user == null) { return(HttpNotFound()); } if (CheckDeleteUser(_user) == true) { if (ModelState.IsValid) { var _result = new UserDAO().Delete(_user.Id); if (_result) { SetAlert("Xóa người dùng thành công", "success"); new SystemLogDAO().Insert("Thêm người dùng [" + _user.UserName + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); } else { SetAlert("Xóa người dùng không thành công", "warning"); } } } return(PartialView("Delete", new UserDAO().GetAllUserPageList())); }
public ActionResult DeleteConfirmed(int id) { Exam exam = new ExamDAO().GetExamById(id); var _session = Session[ConstantVariable.USER_SESSION] as UserLogin; if (_session != null) { if (_session.UserID != exam.UserID && _session.UserID != 1) { ModelState.AddModelError("", "Xóa kỳ thi không thành công. Lỗi: bạn không có quyền xóa kỳ thi này"); } } if (exam.TestResultDetails.Count > 0) { ModelState.AddModelError("", "Xóa kỳ thi không thành công. Lỗi: kỳ thi này đã có người thi không thể xóa"); } if (exam.Tests.Count > 0) { ModelState.AddModelError("", "Xóa kỳ thi không thành công. Lỗi: kỳ thi này có đề thi tham chiếu đến"); } if (ModelState.IsValid) { var result = new ExamDAO().Delete(exam); if (result) { SetAlert("Xóa kỳ thi thành công", "success"); new SystemLogDAO().Insert("Xóa kỳ thi [" + exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); RedirectToAction("Index", "exams"); } else { SetAlert("Xóa kỳ thi không thành công", "warning"); RedirectToAction("Index", "exams"); } } return(RedirectToAction("Index")); }
public ActionResult Create(Subject subject) { var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; if (CheckInputSubject(subject)) { var _subjectDao = new SubjectDAO(); if (ModelState.IsValid) { var _result = _subjectDao.Insert(subject); if (_result > 0) { var s = new SubjectDAO().GetSubjectById(_result); SetAlert("Thêm môn học thành công", "success"); new SystemLogDAO().Insert("Tạo môn học thành công [Môn học: " + s.Name + "] [Năm học: " + s.Grade.SchoolYear.NameOfSchoolYear + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/subjects/details/" + _result)); } else { SetAlert("Thêm lớp học không thành công", "warning"); return(RedirectToAction("Index")); } } } SetSchoolYearViewBag(); SetGradeViewBag(); return(View(subject)); }
public ActionResult Create(Class _class) { var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; var _classDao = new ClassDAO(); if (CheckInputClass(_class)) { if (ModelState.IsValid) { var _result = _classDao.Insert(_class); if (_result > 0) { SetAlert("Thêm lớp học thành công", "success"); new SystemLogDAO().Insert("Thêm lớp học [" + new GradeDAO().GetByClass(_class).SchoolYear.NameOfSchoolYear + "]" + "[" + _class.Name + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/class/details/" + _result)); } else { SetAlert("Thêm lớp học không thành công", "warning"); return(RedirectToAction("Index")); } } } SetSchoolYearViewBag(); SetGradeViewBag(); return(View(_class)); }
public ActionResult Edit(Exam exam) { if (String.IsNullOrEmpty(exam.Titile)) { ModelState.AddModelError("", "Tiêu đề kỳ thi không được để trống."); } if (exam.SelectedClassID == null) { ModelState.AddModelError("", "Vui lòng chọn thí sinh cho kỳ thi này."); } if (ModelState.IsValid) { var _session = Session[ConstantVariable.USER_SESSION] as UserLogin; var _userDao = new UserDAO(); var _examDao = new ExamDAO(); if (_session != null) { exam.ModifiedBy = _session.UserName; } exam.ModifiedDate = DateTime.Now; var _result = _examDao.Update(exam, exam.SelectedClassID); if (_result) { SetAlert("Cập nhật thông tin kỳ thi thành công", "success"); new SystemLogDAO().Insert("Cập nhật kỳ thi [" + exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/exams/details/" + exam.Id)); } else { SetAlert("Sửa kỳ thi không thành công", "warning"); return(RedirectToAction("Index")); } } SetGradeViewBag(); SetSubjectViewBag(exam.SubjectID); SetSchoolYearViewBag(); SetUserViewBag(exam.UserID); SetClassViewBag(exam.SelectedClassID); return(View(exam)); }
public ActionResult DeleteConfirmed(int id) { var _class = new ClassDAO().GetClassById(id); var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; var _result = new ClassDAO().Delete(id); if (_result) { SetAlert("Xóa lớp học thành công", "success"); new SystemLogDAO().Insert("Xóa lớp học [" + _class.Grade.SchoolYear.NameOfSchoolYear + "]" + "[" + _class.Name + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); } else { SetAlert("Lỗi: lớp học tồn tại học sinh. Không thể xóa lớp học này.", "warning"); } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Name,GradeID,Status")] Class _class) { var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; Class c = new ClassDAO().GetClassById(_class.Id); if (CheckInputClass(_class)) { if (ModelState.IsValid) { var _result = new ClassDAO().Update(_class); if (_result) { SetAlert("Cập nhật thông tin lớp học thành công", "success"); new SystemLogDAO().Insert("Sửa lớp học [" + c.Grade.SchoolYear.NameOfSchoolYear + "]" + "[" + _class.Name + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/class/details/" + _class.Id)); } else { SetAlert("Cập nhật thông tin lớp học không thành công", "warning"); return(Redirect("/admin/class")); } } else { SetAlert("Cập nhật thông tin lớp học không thành công", "error"); return(Redirect("/admin/class")); } } SetGradeViewBag(_class.GradeID); SetSchoolYearViewBag(c.Grade.SchoolYear.Id); return(View(_class)); }
public ActionResult Create(User user) { if (CheckInputUser(user) == true) { var _userDao = new UserDAO(); if (ModelState.IsValid) { var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; var _passWordHash = Encode.MD5Hash(user.PasswordHash); int _id = 0; user.PasswordHash = _passWordHash; user.ConfirmPasswordHash = _passWordHash; user.DateOfParticipation = DateTime.Now; if (_userSession != null) { user.CreateBy = _userSession.UserName; } _id = _userDao.Insert(user); if (_id > 0) { SetAlert("Thêm người dùng thành công.", "success"); new SystemLogDAO().Insert("Thêm người dùng [" + user.UserName + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(RedirectToAction("Index", "user")); } else { ModelState.AddModelError("success", "Thêm người không dùng thành công."); } } } SetSchoolYearViewBag(); SetGradeViewBag(); SetClassViewBag(); SetGroupIDViewBag(); return(View(user)); }
public ActionResult Edit(Subject subject) { var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; if (CheckInputSubject(subject)) { if (ModelState.IsValid) { var _result = new SubjectDAO().Update(subject); if (_result) { var s = new SubjectDAO().GetSubjectById(subject.Id); SetAlert("Cập nhật thông tin môn học thành công", "success"); new SystemLogDAO().Insert("Cập nhật môn học thành công [" + s.Name + "] [Năm học: " + s.Grade.SchoolYear.NameOfSchoolYear + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/subjects/details/" + subject.Id)); } else { SetAlert("Cập nhật thông tin môn học không thành công", "warning"); return(Redirect("/admin/subjects")); } } } SetGradeViewBag(subject.GradeID); var _grade = new GradeDAO().GetBySubject(subject); SetSchoolYearViewBag(_grade.SchoolYearID); return(View(subject)); }
public ActionResult StartTheTest(Test test) { var _test = new TestDAO().GetTestByCodeTest(test.CodeTest, test.ExamID); var _testResultDAO = new TestResultDetailDAO(); var _testResult = new TestResultDetail(); if (_test != null) { _test.UserAnswer = test.UserAnswer; _test.ExamID = test.ExamID; _test.CodeTest = test.CodeTest; } var _session = Session[ConstantVariable.USER_SESSION] as UserLogin; if (_session != null) { _testResult.UserID = _session.UserID; } _testResult.TestID = _test.Id; _testResult.ExamID = _test.ExamID; int _answerCorrectNum = 0; int _answerWrongNum = 0; int _answerIgnoredNum = 0; var listQuiz = new TestDAO().GetAllQuiz(_test.Id); if (_test.UserAnswer == null || _test.UserAnswer.Count <= 0) { _answerIgnoredNum = listQuiz.Count; } else { for (int i = 0; i < _test.UserAnswer.Count; i++) { if (listQuiz[i].KeyAnswer == _test.UserAnswer[i]) { _answerCorrectNum++; } else { _answerWrongNum++; } } _answerIgnoredNum = listQuiz.Count - (_answerCorrectNum + _answerWrongNum); } _testResult.Score = _answerCorrectNum * (_test.ScoreLadder.Score / _test.NumberOfQuestions); _testResult.NumberOfWrong = _answerWrongNum; _testResult.NumberOfCorrect = _answerCorrectNum; _testResult.NumberOfIgnored = _answerIgnoredNum; var _countTimeToTake = new TestResultDetailDAO().GetAll(_session.UserID, _test.ExamID); if (_countTimeToTake == null) { _testResult.TimeToTake = 0; } else { _testResult.TimeToTake = _countTimeToTake.Count + 1; } _testResult.ActualTestDate = DateTime.Now; _testResult.ActualStartTime = null; _testResult.ActualEndTime = DateTime.Now.TimeOfDay; for (int i = 0; i < listQuiz.Count; i++) { if (i != listQuiz.Count - 1) { _testResult.UserAnswer += _test.UserAnswer[i] + ","; } else { _testResult.UserAnswer += _test.UserAnswer[i]; } } int _id = _testResultDAO.Insert(_testResult); // Insert if (_id > 0) { var _testDb = new TestDAO().GetTestById(_testResult.TestID); new SystemLogDAO().Insert("Người dùng thi online [Kỳ thi: " + _testDb.Exam.Titile + "] [Môn thi: " + _testDb.Exam.Subject.Name + "] [Mã đề: " + _testDb.CodeTest + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/exams/resultdetail/" + _id)); } return(Redirect("/")); }
public ActionResult DeleteConfirmed(int id) { var subject = new SubjectDAO().GetSubjectById(id); var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; var _result = new SubjectDAO().Delete(id); if (_result == 0) { SetAlert("Xóa môn học thành công", "success"); new SystemLogDAO().Insert("Xóa môn học thành công [" + subject.Name + "] [Năm học: " + subject.Grade.SchoolYear.NameOfSchoolYear + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); } else if (_result == 1) { SetAlert("Lỗi: môn học tồn tại đề thi. Không thể xóa môn học này.", "error"); } else if (_result == 2) { SetAlert("Lỗi: môn học tồn tại câu hỏi. Không thể xóa môn học này.", "error"); } return(RedirectToAction("Index")); }
public ActionResult Create(Exam exam) { if (CheckInputExam(exam)) { if (ModelState.IsValid) { var _session = Session[ConstantVariable.USER_SESSION] as Common.UserLogin; var _userDao = new UserDAO(); var _examDao = new ExamDAO(); if (_session != null) { exam.UserID = _userDao.GetUserByUserName(_session.UserName).Id; } if (!String.IsNullOrEmpty(exam.Note)) { exam.NoteEncode = Encode.StripHTML(exam.Note); } exam.CreatedDate = DateTime.Now; var _result = _examDao.Insert(exam, exam.SelectedClassID); if (_result) { SetAlert("Thêm kỳ thi thành công", "success"); new SystemLogDAO().Insert("Thêm kỳ thi [" + exam.Titile + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/exams/details/" + exam.Id)); } else { ModelState.AddModelError("", "Thêm kỳ thi không thành công."); } } } SetGradeViewBag(); SetSubjectViewBag(exam.SubjectID); SetSchoolYearViewBag(); SetUserViewBag(exam.UserID); SetClassViewBag(exam.SelectedClassID); return(View(exam)); }
public ActionResult Info([Bind(Include = "Id,PasswordHash,NewPasswordHash,ConfirmPasswordHash,Email,DayOfBirth,Phone,FullName,Sex,Avatar,ModifiedBy")] User user) { if (CheckSession(user.Id) == false) { return(RedirectToAction("AccessDenied", "error")); } if (user == null) { return(HttpNotFound()); } var _userDao = new UserDAO(); var _userCurr = _userDao.GetUserById(user.Id); var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; if (!String.IsNullOrEmpty(user.NewPasswordHash) && !String.IsNullOrEmpty(user.ConfirmPasswordHash)) { if (String.Compare(user.NewPasswordHash, user.ConfirmPasswordHash, true) != 0) { ModelState.AddModelError("", "Mật khẩu chưa trùng khớp."); } else // Update user có cập nhật mật khẩu mới { var _newPassWordHash = Encode.MD5Hash(user.NewPasswordHash); user.PasswordHash = _newPassWordHash; //Gán mật khẩu mới vào cột PasswordHash user.NewPasswordHash = null; user.ConfirmPasswordHash = null; user.ModifiedBy = _userSession.UserName; // Giữ lại các trường không đổi user.UserName = _userCurr.UserName; user.ClassID = _userCurr.ClassID; user.Class = _userCurr.Class; user.CreateBy = _userCurr.CreateBy; user.GroupID = _userCurr.GroupID; user.UserGroup = _userCurr.UserGroup; user.Status = _userCurr.Status; user.DateOfParticipation = _userCurr.DateOfParticipation; var _result = _userDao.Update(user); if (_result == true) { _userSession.Avatar = null; _userSession.Avatar = user.Avatar; SetAlert("Cập nhật người dùng thành công.", "success"); new SystemLogDAO().Insert("Người dùng [" + _userSession.UserName + "]" + " cập nhật thông tin [" + user.UserName + "] thành công", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(View(user)); } else { ModelState.AddModelError("", "Cập nhật người dùng không thành công."); } } } else if (String.IsNullOrEmpty(user.NewPasswordHash) && String.IsNullOrEmpty(user.ConfirmPasswordHash)) // Ko cập nhật mật khẩu { user.ModifiedBy = _userSession.UserName; // Giữ lại các trường không đổi user.UserName = _userCurr.UserName; user.ClassID = _userCurr.ClassID; user.Class = _userCurr.Class; user.CreateBy = _userCurr.CreateBy; user.GroupID = _userCurr.GroupID; user.UserGroup = _userCurr.UserGroup; user.Status = _userCurr.Status; user.DateOfParticipation = _userCurr.DateOfParticipation; var _result = _userDao.Update(user, null); if (_result == true) { SetAlert("Sửa thông tin người dùng thành công.", "success"); new SystemLogDAO().Insert("Người dùng [" + _userSession.UserName + "]" + " cập nhật thông tin [" + user.UserName + "] thành công", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(View(user)); } else { ModelState.AddModelError("", "Cập nhật người dùng không thành công."); } } else { ModelState.AddModelError("", "Vui lòng nhập vào mật khẩu mới và xác nhận mật khẩu vào ô bên dưới."); } return(View(user)); }
public ActionResult Edit(Question question) { if (ModelState.IsValid) { var _session = Session["USER_SESSION"] as UserLogin; var _quizDao = new QuizDAO(); question.ContentQuestionEncode = Encode.StripHTML(question.ContentQuestion); question.AnswerTextEncode = Encode.StripHTML(question.AnswerText); question.KeyAnswer = question.KeyAnswer.ToUpper(); if (_session != null) { question.ModifiedBy = _session.UserName; } question.ModifiedDate = DateTime.Now; var _result = _quizDao.Update(question); if (_result == true) { SetAlert("Chỉnh sửa câu hỏi thành công.", "success"); new SystemLogDAO().Insert("Sửa câu hỏi thành công [ID = " + question.Id + "] [ID môn học: " + question.SubjectsID + "]", _session.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/quiz/details/" + question.Id)); } else { SetAlert("Chỉnh sửa câu hỏi không thành công.", "error"); return(Redirect("/admin/quiz")); } } SetSubjectViewBag(question.SubjectsID); SetGradeViewBag(question); SetCategoryViewBag(question.CategoryID); SetKindViewBag(question.KindID); SetLevelViewBag(question.LevelID); SetAnswerChoiceNumViewBag(question.AnswerChoiceNum); return(View(question)); }
//Logout public ActionResult logout() { var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; if (_userSession != null) { new SystemLogDAO().Insert("Người dùng [" + _userSession.UserName + "] đăng xuất khỏi hệ thống", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); } Session[ConstantVariable.USER_SESSION] = null; return(Redirect("/admin/login")); }
public ActionResult Edit(User user) { var _userDao = new UserDAO(); var _userCurr = _userDao.GetUserById(user.Id); if (!String.IsNullOrEmpty(user.NewPasswordHash) && !String.IsNullOrEmpty(user.ConfirmPasswordHash)) { if (String.Compare(user.NewPasswordHash, user.ConfirmPasswordHash, true) != 0) { ModelState.AddModelError("", "Mật khẩu chưa trùng khớp."); } else // Update user có cập nhật mật khẩu mới { if (ModelState.IsValid) { var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; var _newPassWordHash = Encode.MD5Hash(user.NewPasswordHash); user.PasswordHash = _newPassWordHash; //Gán mật khẩu mới vào cột PasswordHash user.NewPasswordHash = _userCurr.PasswordHash; //Gán mật khẩu cũ vào NewPasswordHash user.ConfirmPasswordHash = null; user.ModifiedBy = _userSession.UserName; //Các trường không đổi user.UserName = _userCurr.UserName; user.DateOfParticipation = _userCurr.DateOfParticipation; user.CreateBy = _userCurr.CreateBy; var _result = _userDao.Update(user); if (_userSession.UserID == user.Id) { _userSession.Avatar = null; _userSession.Avatar = user.Avatar; } if (_result == true) { SetAlert("Cập nhật người dùng thành công.", "success"); new SystemLogDAO().Insert("Sửa người dùng [" + user.UserName + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/user/detail/" + user.Id)); } else { ModelState.AddModelError("", "Cập nhật người dùng không thành công."); } } } } else if (String.IsNullOrEmpty(user.NewPasswordHash) && String.IsNullOrEmpty(user.ConfirmPasswordHash)) // Ko cập nhật mật khẩu { if (ModelState.IsValid) { var _userSession = Session[ConstantVariable.USER_SESSION] as UserLogin; user.ModifiedBy = _userSession.UserName; //Các trường không đổi user.UserName = _userCurr.UserName; user.DateOfParticipation = _userCurr.DateOfParticipation; user.CreateBy = _userCurr.CreateBy; var _result = _userDao.Update(user, null); if (_result == true) { SetAlert("Sửa thông tin người dùng thành công.", "success"); if (_userSession.UserID == user.Id) { _userSession.Avatar = null; _userSession.Avatar = user.Avatar; } new SystemLogDAO().Insert("Sửa người dùng [" + user.UserName + "]", _userSession.UserName, DateTime.Now.TimeOfDay, DateTime.Now.Date, GetIPAddress.GetLocalIPAddress()); return(Redirect("/admin/user/detail/" + user.Id)); } else { ModelState.AddModelError("", "Cập nhật người dùng không thành công."); } } } else { ModelState.AddModelError("", "Vui lòng nhập vào mật khẩu mới và xác nhận mật khẩu vào ô bên dưới."); } var _class = new ClassDAO().GetClassById(user.ClassID); var _grade = new GradeDAO().GetByClass(_class); SetSchoolYearViewBag(_grade.SchoolYearID); SetGradeViewBag(_grade.Id); SetClassViewBag(user.ClassID); SetGroupIDViewBag(user.GroupID); return(View(user)); }