Ejemplo n.º 1
0
        protected void Add_ServerClick(object sender, EventArgs e)
        {
            string          DeadLine = txt_DeadLine.Value;
            string          json     = hid_json.Value;
            List <Question> que      = JsonHelper.DeserializeJsonToObject <List <Question> >(json);

            //添加作业表
            Exam exam = new Exam();

            exam.Etime    = DateTime.Now;
            exam.DeadLine = Convert.ToDateTime(DeadLine);
            //i 是作业Id
            int i = new ExamFacade().AddExam(exam);

            QuestionFacade qf = new QuestionFacade();
            //根据作业id 添加题目表

            int j = 1;

            foreach (Question item in que)
            {
                item.Qnum = j++;
                item.Eid  = i;
                item.Time = DateTime.Now;

                qf.AddQuestion(item);
            }
        }
Ejemplo n.º 2
0
        public ActionResult OpenResult(int id)
        {
            var testResult = resultFacade.GetResultWithId(id);
            var resList    = testResult.ResultString.Split(';');

            resList = resList.Take(resList.Length - 1).ToArray();
            var arrRes = resList.Select(s => s.Split(','))
                         .Select(strings => new CheckboxModel {
                Id = int.Parse(strings[0]), Selected = Convert.ToBoolean(strings[1])
            })
                         .ToArray();



            var testTmp = testFacade.GetTestTemplateById(testResult.TestTemplateId);
            var que     = new QuestionFacade().GetListOfQuestionsByTheirAnswers(arrRes.Select(s => s.Id).ToList());
            var blres   = new List <bool>();
            var answers = que.SelectMany(s => s.Answers).ToList();

            for (int i = 0; i < answers.Count(); i++)
            {
                blres.Add(answers[i].Correct == arrRes[i].Selected);
            }



            var model = new ResultModel
            {
                Id             = testTmp.Id,
                Name           = testTmp.Name,
                CompletionTime = testTmp.CompletionTime,
                Date           = testTmp.Date,
                NumOfQuestions = testTmp.NumOfQuestions,
                Questions      = que,
                Answers        = arrRes,
                ResultBools    = blres,
                Score          = testResult.ResultPoints
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult TakeTest(int id)
        {
            var testTmp = testFacade.GetTestTemplateById(id);

            var time2 = testTmp.Date + testTmp.CompletionTime;


            if (DateTime.Now > time2 || DateTime.Now < testTmp.Date)
            {
                TempData["error"] = "Cannot start the test!";
                return(RedirectToAction("Index"));
            }



            var que = new QuestionFacade().GetNumOfRandQuestionsFromThematicAreas(testTmp.NumOfQuestions, testTmp.ThematicAreas);

            var answs = que.SelectMany(s => s.Answers)
                        .Select(tmp => new CheckboxModel {
                Id = tmp.Id, Selected = false
            })
                        .ToArray();


            var model = new TestActiveModel
            {
                Id             = testTmp.Id,
                Name           = testTmp.Name,
                CompletionTime = testTmp.CompletionTime,
                Date           = testTmp.Date,
                NumOfQuestions = testTmp.NumOfQuestions,
                Questions      = que,
                Answers        = answs
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var themAreaFac = new ThematicAreaFacade();

            var questionFac = new QuestionFacade();
            var studgrpFac  = new StudentGroupFacade();
            var ansFac      = new AnswerFacade();
            var userFac     = new UserFacade();
            var testTempFac = new TestTemplateFacade();


            var que1 = new QuestionDTO()
            {
                Text = "EleGiggle"
            };
            var que2 = new QuestionDTO()
            {
                Text = "Keepo"
            };

            var pogChamp = new QuestionDTO()
            {
                Text = "Kappa"
            };
            var stud = new UserDTO
            {
                Email    = "[email protected]",
                Name     = "EleGiggle",
                Surname  = "FrankerZ",
                Password = "******",
                Code     = null,
                UserName = "******",
            };


//
//			var kappa = new StudentGroupDTO { Name = "StudGroup101" };
//			kappa.Students.Add(stud);
//
//			kappa.Tests.Add(new TestTemplateDTO {Name = "gachiGASM" , Date = DateTime.Now});
//			var test = new TestTemplateDTO {Name = "dasdaaaaaaaaa",Date = DateTime.Now };



            var roleManager = new AppRoleManager(new AppRoleStore(new AppDbContext()));

            if (!roleManager.RoleExists("admin"))
            {
                Console.WriteLine("admin role added");
                roleManager.Create(new AppRole {
                    Name = "admin"
                });
            }
            if (!roleManager.RoleExists("student"))
            {
                Console.WriteLine("student role added");

                roleManager.Create(new AppRole {
                    Name = "student"
                });
            }



            //			studgrpFac.CreateStudentGroup(kappa);
            //			questionFac.CreateManyQuestions(new List<QuestionDTO> { que1, que2, pogChamp }, "Twitch");


            //			userFac.Register(new UserDTO
            //						{
            //							Email = "*****@*****.**",
            //							Name = "Kapper",
            //							Surname = "PogChamp",
            //							Password = "******",
            //							Code = "Kappa",
            //							UserName = "******",
            //
            //						});
            //
            //
            var testTemp = new TestTemplateDTO
            {
                Name           = "MyFirstRealTest",
                CompletionTime = new TimeSpan(1, 1, 1),
                Date           = DateTime.Now,
                NumOfQuestions = 5,
                ThematicAreas  = new List <ThematicAreaDTO>
                {
                    new ThematicAreaDTO
                    {
                        Name = "Twitch"
                    }
                }
            };
            var studgrp = new StudentGroupDTO
            {
                Name  = "AllStudents",
                RegId = 420
            };
            //studgrpFac.CreateStudentGroup(studgrp);



//			foreach (var studentGroup in userFac.GetAllUsers())
//			{
//				Console.WriteLine(studentGroup.Name);
//			}



//			for (int i = 0; i < 10; i++)
//			{
//				var quest = new QuestionDTO
//				{
//					Answers = new List<AnswerDTO>
//				{
//					new AnswerDTO
//					{
//
//						Text = "C2 "+i,
//						Correct = true
//					},
//					new AnswerDTO
//					{
//						Text = "CC2"+i,
//						Correct = false
//					},
//					new AnswerDTO
//					{
//						Text = "CC3"+i,
//						Correct = false
//					}
//					,
//					new AnswerDTO
//					{
//						Text = "CC4 "+i,
//						Correct = false
//					}
//				}
//				,
//					Text = "C#2  Qnum =>"+i,
//					OneAnswer = true,
//					Points = 5
//				};
//
//				questionFac.CreateQuestion(quest, "C#2");
//			}

//			Console.WriteLine(testTempFac.CreateTestTemplate(new TestTemplateDTO
//			{
//				Name = "NewFag",NumOfQuestions = 5
//			}));
//
//			var quest=new QuestionDTO
//			{
//				Text = "AAAAAAAAAAAAAAA",
//
//				Points = 2,OneAnswer = true
//			};
//			int id =questionFac.CreateQuestion(quest,"Twitch");
//			var nuQ = questionFac.GetQuestionById(id);
//
//			questionFac.AddAnswerToQuestion(nuQ,new AnswerDTO
//			{
//				Text = "aaaaaaaaaaaaaaaaaaaaaaaaa"
//			});
//
//
//			var nuQ2 = questionFac.GetQuestionById(id);
//			Console.WriteLine("/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\");
//			foreach (var answer in nuQ2.Answers)
//			{
//				Console.WriteLine("ans ->"+answer.Text);
//			}



            //			var quest3 = questionFac.GetQuestionById(3);
            //
            //			 var ans = new AnswerDTO
            //			 {
            //				 Correct = true,
            //				 Description = " ayyy almao1",
            //				 Text = "TriHard",
            //				 Question = quest3
            //
            //			 };
            //			ansFac.CreateAnswer(ans);
            //
            //			ans = new AnswerDTO
            //			{
            //				Correct = true,
            //				Description = "Top KEK",
            //				Text = "4Head",
            //				Question = quest3
            //
            //			};
            //			ansFac.CreateAnswer(ans);
            //
            //
            //
            //
            //
            //			quest3 = questionFac.GetQuestionById(2);
            //
            //			ans = new AnswerDTO
            //			{
            //				Correct = true,
            //				Description = " ayyy almao2",
            //				Text = "haHAA",
            //				Question = quest3
            //
            //			};
            //			ansFac.CreateAnswer(ans);
            //
            //
            //
            //
            //			quest3 = questionFac.GetQuestionById(1);
            //
            //			ans = new AnswerDTO
            //			{
            //				Correct = true,
            //				Description = " ayyy almao3",
            //				Text = "KevinTurtle",
            //				Question = quest3
            //
            //			};
            //			ansFac.CreateAnswer(ans);
            //			testTempFac.CreateTestTemplate(testTemp);


            //testTempFac.AddTheme(testTemp,"LUL");

            //stud.StudentGroups.Add(kappa);
            //			studFac.CreateStudent(stud);
            //			teachFac.CreateTeacher(teacher);

            //			var test = kappa.Tests.First();
            //			test.Date=new DateTime(0);

            //


            //teachFac.DeleteTeacher(teacher);



            //			questionFac.RemoveAllQuestions();
            //			themAreaFac.RemoveAllThematicAreas();
            //			testTempFac.RemoveAllTestTemplates();



            //						testTempFac.CreateTestTemplate(test);

            /*
             *                      themAreaFac.CreateThematicArea("forsenW");
             *
             *                      themAreaFac.CreateThematicArea("forsenK");
             *                      themAreaFac.CreateThematicArea("forsenC");
             *
             *
             *                      questionFac.CreateQuestion(que1,"forsenW");
             *                      questionFac.CreateQuestion(que2, "forsenW");
             *                      questionFac.CreateQuestion(pogChamp, "ForsenC");
             */
            //Console.WriteLine(questionFac.GetQuestionById(1).ThematicArea.Name+" kappa"+questionFac.GetQuestionById(1).Id);

            //studgrpFac.CreateStudentGroup(kappa);

//			var tt=new TestTemplateDTO
//			{
//				Name = "asdfa",
//				NumOfQuestions = 5,
//				ThematicAreas = new List<ThematicAreaDTO>
//				{
//					new ThematicAreaDTO
//					{
//						Name = "Twitch"
//					},
//					new ThematicAreaDTO
//					{
//						Name = "forsen"
//					},
//					new ThematicAreaDTO
//					{
//						Name="Billy"
//					}
//				}
//			};
//			int id =testTempFac.CreateTestTemplate(tt);
//
//			Console.WriteLine("after create");
//			foreach (var dto in testTempFac.GetTestTemplateById(id).StudentGroups)
//			{
//				Console.WriteLine(dto.Name);
//			}
//
//			testTempFac.AddStudentGroup(id,new StudentGroupDTO
//			{
//				Name = "blaze it",
//				RegId = 13
//			});
//			Console.WriteLine("after update");
//
//			foreach (var dto in testTempFac.GetTestTemplateById(id).StudentGroups)
//			{
//				Console.WriteLine(dto.Name);
//
//			}



            //			var tt2 = testTempFac.GetTemplateByName(tt.Name);
            //
            //
            //			Console.WriteLine("///////////");
            //			tt2.ThematicAreas.Add(new ThematicAreaDTO
            //			{
            //				Name = "Billy"
            //			});
            //
            //			testTempFac.UpdateTestTemplate(tt2);


            var themAreas = themAreaFac.GetAllThematicAreas();
            var questions = questionFac.GetAllQuestions();
            var studGrp   = studgrpFac.GetAllStudentGroups();


            var allTests = testTempFac.GetAllTestTemplates();



            //			var qs = questionFac.GetNumOfRandQuestionsFromThematicAreas(5, testTemp.ThematicAreas);
            //			foreach (var q in qs)
            //			{
            //				Console.WriteLine(q.Text);
            //
            //			}


//			foreach (var i in testTempFac.GetAllTestTemplates())
//			{
//				Console.WriteLine("testTemp name :" + i.Name);
//				foreach (var thematicAreaDto in i.ThematicAreas)
//				{
//					Console.WriteLine(thematicAreaDto.Name);
//				}
//			}

            Console.WriteLine("////////////////////////////");

//			Console.WriteLine("Stávající theme areas:");
//			foreach (var item in themAreas)
//			{
//				Console.WriteLine("   {0}  countQ:{1}", item.Name, item.Questions.Count);
//
//				foreach (var q in item.Questions)
//				{
//					Console.WriteLine("     "+q.Text);
//				}
//			}
//			Console.WriteLine("questions:");
//			foreach (var q in questions)
//			{
//				Console.WriteLine(@"   {0} area:{1}", q.Text, q.ThematicArea.Name);
//			}
//			Console.WriteLine("studgroups:");
//
//
//			foreach (var q in studGrp)
//			{
//				Console.WriteLine($"   studgrp name{ q.Name} ");
//
//				Console.WriteLine("      studs ");
//				foreach (var st in q.Students)
//				{
//					Console.WriteLine("        " + st.Name);
//				}
//
//				Console.WriteLine("      tests ");
//				foreach (var st in q.Tests)
//				{
//					Console.WriteLine("        " + st.Name +"  DATE FAGGOTINA   "+ st.Date);
//					Console.WriteLine("kapaaaa");
//				}
//			}
//
//
//
//
//
//			Console.WriteLine(" studs :");
//
//
//
//
//
//
//			Console.WriteLine(" testTemps :");
//			foreach (var q in allTests)
//			{
//				Console.WriteLine($"   testTemp name{ q.Name} " + "  DATE FAGGOTINA   " + q.Date);
//
//
//
//				Console.WriteLine("      themAreas ");
//				foreach (var st in q.ThematicAreas)
//				{
//					Console.WriteLine("        " + st.Name);
//				}
//			}
//
//
            Console.WriteLine("all done");
            Console.ReadKey();
        }
 public QuestionController(QuestionFacade questionFacade)
 {
     this.questionFacade = questionFacade;
 }
 public QuestionController(DBContext context)
 {
     this.context        = context;
     this.questionFacade = new QuestionFacade(context);
 }
 public QuestionController(QuestionFacade questionFacade, TopicFacade topicFacade, AnswerFacade answerFacade)
 {
     this.questionFacade = questionFacade;
     this.topicFacade    = topicFacade;
     this.answerFacade   = answerFacade;
 }