public ResponseModel <ExamQuestionModel> Save(List <QuestionsList> modelList, long TestId) { ResponseModel <ExamQuestionModel> result = new ResponseModel <ExamQuestionModel> { Data = new ExamQuestionModel() }; try { foreach (var model in modelList) { ExamQuestions db = new ExamQuestions(); db.ExamId = TestId; db.Question = model.Name; db.CreatedOn = DateTime.Now; db.IsActive = true; _context.ExamQuestions.Add(db); } modelList = null; _context.SaveChanges(); result = new ResponseModel <ExamQuestionModel> { status = true, message = "Success" }; } catch (Exception ex) { result.status = false; result.message = ex.Message; } return(result); }
public string Delete(int ID) { string message = string.Empty; using (QuestionBankDbContext Db = new QuestionBankDbContext()) { Lesson ders = Db.Lesson.SingleOrDefault(x => x.ID.Equals(ID)); if (ders != null) { IEnumerable <UserLesson> dersles = Db.UserLesson.RemoveRange(Db.UserLesson.Where(x => x.LessonID.Equals(ID))); List <Topic> LstLessonTopics = new List <Topic>(); foreach (var item in ders.Topic) { foreach (var lstquestion in item.Questions) { List <Answers> LstTopicQuestionsAnswers = Db.Answers.RemoveRange(Db.Answers.Where(x => x.QuestionID.Equals(lstquestion.ID))).ToList(); ExamQuestions LstQuestionInExam = Db.ExamQuestions.Remove(Db.ExamQuestions.SingleOrDefault(x => x.QuestionID.Equals(lstquestion.ID))); } List <Question> DeleteTopicQuestions = Db.Question.RemoveRange(Db.Question.Where(x => x.TopicID.Equals(item.ID))).ToList(); List <TopicQuestionPeriod> periods = Db.TopicQuestionPeriod.RemoveRange(Db.TopicQuestionPeriod.Where(x => x.TopicID.Equals(item.ID))).ToList(); LstLessonTopics.Add(item); } Db.Topic.RemoveRange(LstLessonTopics); Db.Lesson.Remove(ders); Db.SaveChanges(); message = JsonConvert.SerializeObject(new { durum = "OK", mesaj = "Ders Silindi" }); } else { message = JsonConvert.SerializeObject(new { durum = "No", mesaj = "Ders Silinemedi" }); } } return(message); }
public string Delete(int ID) { string message = string.Empty; using (QuestionBankDbContext Db = new QuestionBankDbContext()) { Question question = Db.Question.SingleOrDefault(x => x.ID.Equals(ID)); if (question != null) { ExamQuestions LstQuestionInExam = Db.ExamQuestions.SingleOrDefault(x => x.QuestionID.Equals(ID)); if (LstQuestionInExam != null) { Db.ExamQuestions.Remove(LstQuestionInExam); } List <Answers> lstquestionanswers = Db.Answers.RemoveRange(Db.Answers.Where(x => x.QuestionID.Equals(ID))).ToList(); Db.Question.Remove(question); Db.SaveChanges(); message = JsonConvert.SerializeObject(new { durum = "OK", mesaj = "Soru Silindi" }); } else { message = JsonConvert.SerializeObject(new { durum = "No", mesaj = "Soru Silinemedi" }); } } return(message); }
public string Delete(int ID) { string message = string.Empty; using (QuestionBankDbContext Db = new QuestionBankDbContext()) { Topic topic = Db.Topic.SingleOrDefault(x => x.ID.Equals(ID)); if (topic != null) { foreach (var item in topic.Questions) { List <Answers> LstTopicQuestionsAnswers = Db.Answers.RemoveRange(Db.Answers.Where(x => x.QuestionID.Equals(item.ID))).ToList(); ExamQuestions LstQuestionInExam = Db.ExamQuestions.Remove(Db.ExamQuestions.SingleOrDefault(x => x.QuestionID.Equals(item.ID))); } List <Question> LstTopicQuestions = Db.Question.RemoveRange(Db.Question.Where(x => x.TopicID.Equals(ID))).ToList(); List <TopicQuestionPeriod> periods = Db.TopicQuestionPeriod.RemoveRange(Db.TopicQuestionPeriod.Where(x => x.TopicID.Equals(ID))).ToList(); Db.Topic.Remove(topic); Db.SaveChanges(); message = JsonConvert.SerializeObject(new { durum = "OK", mesaj = "Konu Silindi" }); } else { message = JsonConvert.SerializeObject(new { durum = "No", mesaj = "Konu Silinemedi" }); } } return(message); }
public ResponseModel <ExamQuestionModel> Update(List <QuestionsList> modelList, long TestId) { ResponseModel <ExamQuestionModel> result = new ResponseModel <ExamQuestionModel> { Data = new ExamQuestionModel() }; _context.ExamQuestions.Where(x => x.ExamId == TestId).ToList() .ForEach(a => { a.IsActive = false; } ); _context.SaveChanges(); try { foreach (var model in modelList) { if (model.Id > 0) { if (!string.IsNullOrWhiteSpace(model.Name)) { var item = _context.ExamQuestions.Where(e => e.ExamId == TestId && e.QuestionId == model.Id).Select(e => e).FirstOrDefault(); if (item != null) { item.Question = model.Name; item.IsActive = true; result = new ResponseModel <ExamQuestionModel> { status = true, message = "Success" }; } else { result = new ResponseModel <ExamQuestionModel> { status = false, message = "Test Not Found" }; } } } else { ExamQuestions db = new ExamQuestions(); db.ExamId = TestId; db.Question = model.Name; db.CreatedOn = DateTime.Now; db.IsActive = true; _context.ExamQuestions.Add(db); } } _context.SaveChanges(); } catch (Exception ex) { result = new ResponseModel <ExamQuestionModel> { status = false, message = ex.Message.ToString() }; } return(result); }
public void AddQuestionTest() { ExamQuestions examQuestions = new ExamQuestions(Language.FirstLanguage); foreach (var question in TestHelper.ReadCsv()) { examQuestions.AddQuestion(question); } Check.That(examQuestions.Questions().Count()).IsStrictlyGreaterThan(0); }
/// <summary> /// 新增试题 /// </summary> /// <param name="t"></param> /// <returns></returns> public bool Add(ExamQuestions t) { try { return(sugar.Insertable <ExamQuestions>(t).ExecuteCommand() > 0); } catch (Exception ex) { ErrorLog.WriteLog(ex); return(false); } }
/// <summary> /// 根据试卷ID查询 /// </summary> /// <param name="ExamQuestionId"></param> /// <returns></returns> public List <Questions> QueryByEQId(string ExamQuestionId) { ExamQuestions m = examquestion_DAL.QueryByEQId(ExamQuestionId); string[] id = m.QuestionIds.Split(','); List <Questions> li = new List <Questions>(); foreach (var item in id) { var list = questions_DAL.QueryById(int.Parse(item)); li.Add(list); } return(li); }
public async Task <int> SolveExam(ExamQuestions examQuestion, string name) { var exam = this.repository.FirstOrDefault(exam => exam.YearOfCreation == examQuestion.YearOfCreation); var points = 0; for (int i = 0; i < exam.Questions.Count; i++) { var correct = exam.Questions[i].CorrectAnswer - 1; var answer = examQuestion?.Questions[i].Answers.Where(a => a.IsSelected == true).FirstOrDefault(); var actual = Array.IndexOf(examQuestion.Questions[i].Answers.ToArray(), answer); if (correct == actual) { points++; } } var user = await this.userManager.FindByNameAsync(name); var userExam = new UserExam() { ExamId = exam.Id, UserId = user.Id }; if (user.UserExams.FirstOrDefault(x => x.UserId == user.Id) == null && user.UserExams.FirstOrDefault(x => x.ExamId == exam.Id) == null) { userExam = new UserExam() { ExamId = exam.Id, UserId = user.Id, Points = points }; user.UserExams.Add(userExam); await this.repository.SaveChangesAsync(); } else if (user.UserExams.FirstOrDefault(x => x.UserId == user.Id) != null && user.UserExams.FirstOrDefault(x => x.ExamId == exam.Id) != null) { userExam.Points = Math.Max(userExam.Points, points); var userExamFromDb = user.UserExams.FirstOrDefault(x => x.UserId == user.Id && x.ExamId == exam.Id); userExamFromDb.Points = Math.Max(points, userExamFromDb.Points); await this.repository.SaveChangesAsync(); } return(points); }
public void CheckQuestionTest() { ExamQuestions examQuestions = new ExamQuestions(Language.FirstLanguage); foreach (var question in TestHelper.ReadCsv()) { examQuestions.AddQuestion(question); } Check.That(examQuestions.Questions().Count()).IsStrictlyGreaterThan(0); foreach (var question in examQuestions.Questions()) { examQuestions.CheckQuestion(question.FirstLanguageItem, question); } Check.That(examQuestions.Passed()).HasSize(examQuestions.Questions().Count); Check.That(examQuestions.Passed().Where(c => c.Item1.FirstLanguageItem == c.Item2)).HasSize(examQuestions.Questions().Count); }
public ActionResult Add(ExamPrepareViewModel model) { QuestionBankDbContext Db = new QuestionBankDbContext(); PostUserLessonAndPeriod(); if (string.IsNullOrWhiteSpace(model.SinavAdi) || model.SeciliSorular == null) { if (Db.Exam.SingleOrDefault(x => x.ExamName.Equals(model.SinavAdi)) == null) { ViewBag.ErrorMessage = "Bu isimde sınav mevcuttur lütfen başka sınav ismi giriniz."; return(View()); } ViewBag.ErrorMessage = "Lütfen Sınav adı belirleyin veya soru seçiniz..."; return(View()); } else { Exam exam = new Exam() { ExamName = model.SinavAdi }; Db.Exam.Add(exam); List <ExamQuestions> lstQuestions = new List <ExamQuestions>(); foreach (var item in model.SeciliSorular) { ExamQuestions examquestions = new ExamQuestions() { QuestionID = item, ExamID = exam.ID, }; lstQuestions.Add(examquestions); } Db.ExamQuestions.AddRange(lstQuestions); Db.SaveChanges(); ViewBag.Message = exam.ExamName + " Sınavı başarıyla oluşturulmuştur..."; } return(View()); }
public bool Add(string ExamName, string Num, DateTime ExamStartDate, DateTime ExamEndDate, int CollegeId, int MajorId, int StageId) { try { var list = examquestion_BLL.QueryByIds(CollegeId, MajorId, StageId); Random random = new Random(); ArrayList ids = new ArrayList(); var singleNums = 0; var moreNums = 0; var judgeNums = 0; switch (Num) { case "20": singleNums = 10; moreNums = 5; judgeNums = 5; break; case "40": singleNums = 20; moreNums = 10; judgeNums = 10; break; case "60": singleNums = 20; moreNums = 20; judgeNums = 20; break; case "100": singleNums = 40; moreNums = 30; judgeNums = 30; break; } for (int i = 0; i < singleNums; i++) { var index = random.Next(list.Single.Count - 1); ids.Add(list.Single[index].QuestionId); list.Single.RemoveAt(index); } for (int i = 0; i < moreNums; i++) { var index = random.Next(list.More.Count - 1); ids.Add(list.More[index].QuestionId); list.More.RemoveAt(index); } for (int i = 0; i < judgeNums; i++) { var index = random.Next(list.Judge.Count - 1); ids.Add(list.Judge[index].QuestionId); list.Judge.RemoveAt(index); } string str = ""; for (int i = 0; i < ids.Count; i++) { if (i == ids.Count - 1) { str = str + ids[i].ToString(); } else { str = str + ids[i].ToString() + ","; } } //添加试卷到试卷表 ExamQuestions model = new ExamQuestions { ExamName = ExamName, ExamQuestionId = DateTime.Now.Ticks.ToString(), QuestionIds = str, ExamStartDate = ExamStartDate, ExamEndDate = ExamEndDate, CreateDate = DateTime.Now, CollegeId = CollegeId, MajorId = MajorId, StageId = StageId, State = 1 }; var result = examquestion_BLL.Add(model); //写入redis缓存 var examQuestionsList = examquestion_BLL.GetExamQuestions(); var redis = RedisHelper.Set <List <ExamQuestions> >("Exam", examQuestionsList); return(result); } catch (Exception ex) { ErrorLog.WriteLog(ex); return(false); } }
public void Update(ExamQuestions examQuestions) { _unitOfWork.ExamQuestionsRepository.Update(examQuestions); }
public ExamQuestions Add(ExamQuestions examQuestions) { return(_unitOfWork.ExamQuestionsRepository.Add(examQuestions)); }
public bool Add(ExamQuestions m) { return(examquestion_DAL.Add(m)); }
public async Task <IActionResult> SolveExamPost(ExamQuestions exam) { int points = await this.examsService.SolveExam(exam, this.User.Identity.Name); return(this.View("ExamResult", points)); }
public bool Update(ExamQuestions t) { throw new NotImplementedException(); }
public ActionResult OtoAdd(ExamPrepareViewModel model) { QuestionBankDbContext Db = new QuestionBankDbContext(); PostUserLessonAndPeriod(); ModelState.Remove("SeciliSorular"); ModelState.Remove("SoruPuani"); ModelState.Remove("questions"); if (ModelState.IsValid) { if (Db.Exam.SingleOrDefault(x => x.ExamName.Equals(model.SinavAdi)) == null) { List <Question> questions = new List <Question>(); var sorular = Db.Question.ToList().Where(x => x.Topic.LessonID.Equals(model.DersID) && x.QuestionPeriodID.Equals(model.DonemID)).ToList(); foreach (var item in sorular) { int puan = 0; if (item.QuestionType.QuestionTypeName.Equals("Klasik")) { puan = model.KlasikSoruPuan; } else if (item.QuestionType.QuestionTypeName.Equals("Test")) { puan = model.TestSoruPuan; } else if (item.QuestionType.QuestionTypeName.Equals("Boşluk Doldurma")) { puan = model.BoslukSoruPuan; } questions.Add(item); } List <Question> SeciliAdetSoru = new List <Question>(); SeciliAdetSoru.AddRange(sorular.Where(x => x.QuestionType.QuestionTypeName.Equals("Klasik")).OrderBy(x => Guid.NewGuid()).Take(model.KlasikSoruAdet)); SeciliAdetSoru.AddRange(sorular.Where(x => x.QuestionType.QuestionTypeName.Equals("Test")).OrderBy(x => Guid.NewGuid()).Take(model.TestSoruAdet)); SeciliAdetSoru.AddRange(sorular.Where(x => x.QuestionType.QuestionTypeName.Equals("Boşluk Doldurma")).OrderBy(x => Guid.NewGuid()).Take(model.BoslukSoruAdet)); Exam exam = new Exam() { ExamName = model.SinavAdi }; Db.Exam.Add(exam); List <ExamQuestions> SecilmisEklenecekSorular = new List <ExamQuestions>(); foreach (var item in SeciliAdetSoru) { ExamQuestions examQuestions = new ExamQuestions() { QuestionID = item.ID, ExamID = exam.ID, }; SecilmisEklenecekSorular.Add(examQuestions); } Db.ExamQuestions.AddRange(SecilmisEklenecekSorular); Db.SaveChanges(); ViewBag.Message = exam.ExamName + " Sınavı başarıyla oluşturulmuştur..."; } else { ViewBag.EMessage = $"<div class='alert alert-danger'><strong>Böyle bir sınav mevcuttur lütfen yeni bir sınav adı giriniz...!</strong> </div>"; } } else { ViewBag.EMessage = $"<div class='alert alert-danger'><strong>Hata!</strong> </div>"; } return(View("Add")); }
static void Main(string[] args) { studentDb.insert(new Students() { Username = "******", Password = "******", IsItFinished = false }); studentDb.insert(new Students() { Username = "******", Password = "******", IsItFinished = false }); studentDb.insert(new Students() { Username = "******", Password = "******", IsItFinished = true }); studentDb.insert(new Students() { Username = "******", Password = "******", IsItFinished = false }); studentDb.insert(new Students() { Username = "******", Password = "******", IsItFinished = false }); studentDb.insert(new Students() { Username = "******", Password = "******", IsItFinished = true }); studentDb.insert(new Students() { Username = "******", Password = "******", IsItFinished = false }); studentDb.insert(new Students() { Username = "******", Password = "******", IsItFinished = true }); studentDb.insert(new Students() { Username = "******", Password = "******", IsItFinished = true }); GetPoints getPoin = new GetPoints(Validation.ReturnPoints); Questions questions = new Questions(); RegisServices <Students> registerStudent = new RegisServices <Students>(); RegisServices <Teachers> registerTeacher = new RegisServices <Teachers>(); Console.WriteLine("ENTER: 1 - student | 2 - teacher"); int num; bool isItSTudentOrTeacher = int.TryParse(Console.ReadLine(), out num); if (isItSTudentOrTeacher && num == 1) { Students studentOne = new Students(); logs: Console.WriteLine("Register: Press 1, Log in Press 2"); int logNum; bool isItRegister = int.TryParse(Console.ReadLine(), out logNum); if (isItRegister && logNum == 1) { string username; string password; bool IsLessThen = true; while (IsLessThen) { Console.WriteLine("- REGISTER -"); Console.WriteLine("========================="); Console.WriteLine("Enter UserName"); username = Console.ReadLine().Trim(); Console.WriteLine("Enter Password"); password = Console.ReadLine().Trim(); IsLessThen = Validation.IsStringLessThen(username, password); if (IsLessThen == false) { registerStudent.Register(username, password, studentOne); studentDb.insert(studentOne); goto logs; } } } else if (isItRegister && logNum == 2) { Console.WriteLine("- LOG IN -"); Console.WriteLine("========================="); string username; string password; Console.WriteLine("Enter UserName"); username = Console.ReadLine().Trim(); Console.WriteLine("Enter Password"); password = Console.ReadLine().Trim(); registerStudent.LogIn(username, password, studentOne); var student10 = studentDb.GetById(10); Console.ResetColor(); Console.WriteLine(" PRESS ENTER: \n - START TEST -"); Console.WriteLine("========================="); Console.ReadLine(); Console.WriteLine(" QUESTION 1"); Console.WriteLine("____________________"); ExamQuestions.ShowQuestions(0, 1); Console.WriteLine("-------------------------"); Console.Write(" Answare: "); getPoin(1, int.Parse(Console.ReadLine()), 2); Console.WriteLine("-------------------------"); Console.ReadLine(); Console.WriteLine(" QUESTION 2"); Console.WriteLine("____________________"); ExamQuestions.ShowQuestions(1, 2); Console.WriteLine("-------------------------"); Console.Write(" Answare: "); getPoin(2, int.Parse(Console.ReadLine()), 7); Console.WriteLine("-------------------------"); Console.ReadLine(); Console.WriteLine(" QUESTION 3"); Console.WriteLine("____________________"); ExamQuestions.ShowQuestions(2, 3); Console.WriteLine("-------------------------"); Console.Write(" Answare: "); getPoin(3, int.Parse(Console.ReadLine()), 4); Console.WriteLine("-------------------------"); Console.ReadLine(); Console.WriteLine(" QUESTION 4"); Console.WriteLine("____________________"); ExamQuestions.ShowQuestions(3, 4); Console.WriteLine("-------------------------"); Console.Write(" Answare: "); getPoin(4, int.Parse(Console.ReadLine()), 5); Console.WriteLine("-------------------------"); Console.ReadLine(); Console.WriteLine(" QUESTION 5"); Console.WriteLine("____________________"); ExamQuestions.ShowQuestions(4, 5); Console.WriteLine("-------------------------"); Console.Write(" Answare: "); getPoin(5, int.Parse(Console.ReadLine()), 3); Console.WriteLine("-------------------------"); Console.ReadLine(); Console.WriteLine("TEST END"); Console.WriteLine("Thank you about your time and finished the test"); Messages.ShowMessages($"Points = {Validation.Points}", ConsoleColor.Yellow); Messages.ShowMessages(student10.ShowInfo(), ConsoleColor.DarkCyan); Console.ResetColor(); Console.WriteLine("++++++++++++++++++++++++++++++++"); Console.WriteLine("TRUE ANSWARES"); Validation.FirstAnsware(questions); Console.WriteLine("-------------------------"); Console.BackgroundColor = ConsoleColor.White; Messages.ShowMessages("LOG OUT", ConsoleColor.DarkMagenta); Console.ResetColor(); } else { Messages.ShowMessages("ERROR - Incorect input", ConsoleColor.Red); } } else if (isItSTudentOrTeacher && num == 2) { Teachers teacherOne = new Teachers(); logs: Console.WriteLine("Register: Press 1, Log in Press 2"); int logNum; bool isItRegister = int.TryParse(Console.ReadLine(), out logNum); if (isItRegister && logNum == 1) { string username; string password; bool IsLessThen = true; while (IsLessThen) { Console.WriteLine("- REGISTER -"); Console.WriteLine("========================="); Console.WriteLine("Enter UserName"); username = Console.ReadLine().Trim(); Console.WriteLine("Enter Password"); password = Console.ReadLine().Trim(); IsLessThen = Validation.IsStringLessThen(username, password); if (IsLessThen == false) { registerTeacher.Register(username, password, teacherOne); teachersDb.insert(teacherOne); goto logs; } } } else if (isItRegister && logNum == 2) { Console.WriteLine("- LOG IN -"); Console.WriteLine("========================="); string username; string password; Console.WriteLine("Enter UserName"); username = Console.ReadLine().Trim(); Console.WriteLine("Enter Password"); password = Console.ReadLine().Trim(); registerTeacher.LogIn(username, password, teacherOne); var teacher1 = teachersDb.GetById(1); teacherOne.students.AddRange(studentDb.GetAll()); Console.WriteLine(teacher1.ShowInfo()); Console.ResetColor(); Console.WriteLine("============================"); Console.WriteLine("Your students"); teacher1.ShowStudents(); Console.WriteLine("Do you want see wich and how many finished queez? Y/N"); char yesNo = char.Parse(Console.ReadLine().ToUpper().Trim()); if (yesNo == 'Y') { var std = studentDb.GetAll(); Validation.PrintStudentDidQuezzOrNot <Students>(std); } else if (yesNo == 'N') { Messages.ShowMessages("Have a nice day professor. \n \r \r LOG OUT", ConsoleColor.Yellow); Console.ReadLine(); } else { Messages.ShowMessages("ERROR - Invalide Charackter", ConsoleColor.Red); } Messages.ShowMessages("Have a nice day professor. \n \r \r LOG OUT", ConsoleColor.Yellow); Console.ResetColor(); } else { Messages.ShowMessages("ERROR - Incorect input", ConsoleColor.Red); } } else { Messages.ShowMessages("ERROR - Incorect input", ConsoleColor.Red); } Console.ReadLine(); }
public void Delete(ExamQuestions examQuestions) { _unitOfWork.ExamQuestionsRepository.Delete(examQuestions); }