Ejemplo n.º 1
0
        public ActionResult GetLink(QuizLinkView view)
        {
            var quiz = cx.Quizzes.Find(view.Quiz.Id);

            if (quiz == null)
            {
                return(HttpNotFound());
            }

            var reference = cx.QuizReferences.Where(x => x.Quiz.Id == quiz.Id).ToList();

            if (reference.Count != 0)
            {
                cx.QuizReferences.RemoveRange(reference);
            }

            var model = new QuizReference()
            {
                Id           = helper.LinkGenerator(),
                Quiz         = quiz,
                Deadline     = view.Reference.Deadline,
                AttemptCount = view.Reference.AttemptCount,
                Type         = view.Reference.Type
            };

            cx.QuizReferences.Add(model);

            cx.SaveChanges();

            return(RedirectToAction("QuizLink", new { id = quiz.Id }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Contain localhost address
        /// </summary>
        private string GenerateLink(QuizReference reference)
        {
            var baseurl = Request.Url.GetLeftPart(UriPartial.Authority);

            return(baseurl + "/Test/GetTest?link=" + reference.Id);

            //return "https://localhost:44339/Test/GetTest?link=" + reference.Id;
        }
Ejemplo n.º 3
0
        public override void LoadFromWz()
        {
            Logger.Information("Loading Quizzes");

            using var file = GetWzFile("Data.wz");
            file.ParseWzFile();
            var dir = file.WzDirectory.GetDirectoryByName("Etc");
            var img = dir.GetImageByName("OXQuiz.img");

            img.WzProperties.ForEach(quizImg =>
            {
                if (!int.TryParse(quizImg.Name, out var quizId))
                {
                    return;
                }

                var quiz = new QuizReference {
                    Id = quizId
                };

                quizImg.WzProperties.ForEach(questionImg =>
                {
                    if (!int.TryParse(questionImg.Name, out var questionId))
                    {
                        return;
                    }


                    var question = questionImg["q"]?.GetString();
                    var answer   = (questionImg["a"]?.GetInt() ?? 0) > 0;
                    var response = questionImg["d"]?.GetString();
                    quiz.Questions.Add(new QuizQuestionReference
                    {
                        Id = questionId, Question = question, Answer = answer, Response = response
                    });
                });

                Data.Data.Add(quiz.Id, quiz);
            });
        }