public QuizCategory Insert(QuizCategory o)
        {
            var quiz = _quizCategoryRepo.Insert(o);

            _quizCategoryRepo.Save();
            return(quiz);
        }
Esempio n. 2
0
 public static DalQuizCategory ToDalTestCategory(this QuizCategory testCategory)
 {
     return(new DalQuizCategory()
     {
         Id = testCategory.Id, Name = testCategory.Name
     });
 }
Esempio n. 3
0
        public Result List(QuizCategory dto)
        {
            var result = new Result();
            var query  = _quizCategoryRepository.Table
                         .Include(s => s.Quizs);

            if (!string.IsNullOrWhiteSpace(dto.Name))
            {
                query = query.Where(w => w.Name.Contains(dto.Name) || w.Quizs.Count > 1);
            }
            else
            {
                dto.Name = string.Empty;
            }
            query = query.Where(w => w.IsActive);
            query = query.OrderBy(s => s.Name);

            result.Data = query.Select(s => new
            {
                s.Name,
                s.CategoryIcon,
                Quizs = s.Quizs.Where(w => w.IsActive && w.Title.Contains(dto.Name)).OrderBy(o => o.Title)
                        .Select(x => new { x.Title, x.Slug }).ToList()
            }).ToList();

            return(result);
        }
Esempio n. 4
0
    private QuizOption[] GenerateQuizOptions(ResourceRequest request, QuizCategory category)
    {
        // Create the options
        QuizOption[] options = new QuizOption[3];

        // Get the usefulness of the request
        int usefulness = request.Usefulness;

        // The option at the usefulness level has full score
        options[usefulness] = new QuizOption(optionLabels[usefulness], 2);

        if (usefulness != 1)
        {
            // Middle option has score of 1
            options[1] = new QuizOption(optionLabels[1], 1);

            // The other usefulness option has score of 0
            usefulness          = (usefulness + 2) % 4;
            options[usefulness] = new QuizOption(optionLabels[usefulness], 0);
        }
        else
        {
            options[2] = new QuizOption(optionLabels[2], 1);
            options[0] = new QuizOption(optionLabels[0], 0);
        }

        return(options);
    }
 public void Update(QuizCategory category)
 {
     if (category != null && Exists(category.CategoryId))
     {
         db.SaveChanges();
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            QuizCategory quizCategory = db.QuizCategories.Find(id);

            db.QuizCategories.Remove(quizCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public void Delete(QuizCategory category)
 {
     if (category != null)
     {
         db.QuizCategories.Remove(category);
         db.SaveChanges();
     }
 }
Esempio n. 8
0
        internal static string ToSEOName(this QuizCategory quizCategory)
        {
            if (quizCategory == null)
            {
                return(String.Empty);
            }

            return(ToSEOName(quizCategory.Name));
        }
        private void SetCategoryandReturn(QuizCategory category)
        {
            //Return to main menu with chosen category and result code to reflect this
            Intent returnMainResult = new Intent();

            returnMainResult.PutExtra("ChosenCategory", category.ToString());
            SetResult(Result.Ok, returnMainResult);
            Finish();
        }
Esempio n. 10
0
 public void Insert(QuizCategory category)
 {
     if (category == null)
     {
         return;
     }
     db.QuizCategories.Add(category);
     db.SaveChanges();
 }
Esempio n. 11
0
 public ActionResult Edit([Bind(Include = "Id,Category")] QuizCategory quizCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(quizCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(quizCategory));
 }
Esempio n. 12
0
        public ActionResult Create([Bind(Include = "Id,Category")] QuizCategory quizCategory)
        {
            if (ModelState.IsValid)
            {
                db.QuizCategories.Add(quizCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(quizCategory));
        }
Esempio n. 13
0
        public QuizCategoryViewModel ToQuizCategoryViewModel(QuizCategory category)
        {
            var vm = new QuizCategoryViewModel
            {
                Id        = category.Id,
                Name      = category.Name,
                QuizCount = _quizService.GetAll().Count(x => x.Category.Id == category.Id)
            };

            return(vm);
        }
Esempio n. 14
0
        public static QuizCategoryViewModel ToQuizCategoryViewModel(this QuizCategory category, IQuizService quizzes)
        {
            var vm = new QuizCategoryViewModel()
            {
                Id        = category.Id,
                Name      = category.Name,
                QuizCount = quizzes.GetAll().Count(x => x.Category.Id == category.Id)
            };

            return(vm);
        }
Esempio n. 15
0
 public RealTimeQuiz()
 {
     participents = new List <Participent>();
     Questions    = new QuizQuestion[8];
     for (int i = 0; i < 8; i++)
     {
         QuizCategory chosenCategory = Categories[GameServer.RandomNumberGenerator.Next(0, Categories.Length)];
         Questions[i] = chosenCategory.Questions[GameServer.RandomNumberGenerator.Next(0, chosenCategory.Questions.Length)];
     }
     Active = false;
 }
Esempio n. 16
0
 public int GetOrElse(QuizCategory category, int ifNotPresent)
 {
     if (scores.ContainsKey(category))
     {
         return(scores[category]);
     }
     else
     {
         return(ifNotPresent);
     }
 }
 public void Create(QuizCategory category)
 {
     try
     {
         this.categories.Add(category);
         this.Save();
     }
     catch (DbUpdateException ex)
     {
         throw new CategoryManagementException(ex.Message, ex);
     }
 }
Esempio n. 18
0
 public void Create(QuizCategory category)
 {
     try
     {
         this.categories.Add(category);
         this.Save();
     }
     catch (DbUpdateException ex)
     {
         throw new CategoryManagementException(ex.Message, ex);
     }
 }
        public void QuizCategoryService_Insert()
        {
            var service = Mocks.QuizCategoryService;

            var cat = new QuizCategory();

            cat.Name = "name";

            var saved = service.Insert(cat);

            Assert.AreEqual(cat.Name, saved.Name);
            Assert.IsTrue(saved.Id > 0);
        }
Esempio n. 20
0
 public int Add(QuizCategory quizCategory)
 {
     try
     {
         offerRepo.Add(quizCategory);
         offerRepo.Save();
     }
     catch (Exception ex)
     {
         string error = ex.Message;
     }
     return(quizCategory.Id);
 }
Esempio n. 21
0
        // GET: Categories/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            QuizCategory quizCategory = db.QuizCategories.Find(id);

            if (quizCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(quizCategory));
        }
Esempio n. 22
0
        // PUT: Category
        public ActionResult AddCategory(CategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
                //return Json(new { success = false, message = });
            }
            QuizCategory category = new QuizCategory()
            {
                CategoryName = model.CategoryName,
                Image_url    = model.Image_url
            };

            _categoryRepository.Insert(category);

            return(RedirectToAction("Index"));
        }
Esempio n. 23
0
    private bool ResourceRequestGeneratesQuestion(ReviewedResourceRequest review)
    {
        // Get the categories of all fixed quesitons
        IEnumerable <QuizCategory> testedCategories = template.AllQuestions
                                                      .Select(q => q.Category);
        // Create the category this request represents
        QuizCategory myCategory = new QuizCategory(review.Request.ItemAddressed, review.Request.NeedAddressed);

        // Resource request will generate a question
        // if the status is not denied or invalid,
        // and the category of the review is somewhere in the quiz
        return(review.CurrentStatus != ReviewedResourceRequest.Status.Denied &&
               review.CurrentStatus != ReviewedResourceRequest.Status.Invalid &&
               (review.Request.NeedAddressed == NeedType.Terrain ||
                review.Request.NeedAddressed == NeedType.FoodSource) &&
               testedCategories.Contains(myCategory));
    }
Esempio n. 24
0
        public async Task GetCategoryQuestions(QuizCategory quizCategory)
        {
            var categoryQuestions = Questions[quizCategory];

            foreach (var question in categoryQuestions)
            {
                await Clients.Others.SendAsync("receiveQuestion", quizCategory, question, categoryQuestions.Count);

                await Task.Delay(30000);

                var correctAnswer = question.Answers.FirstOrDefault(p => p.AnswerId.Equals(question.CorrectAnswerId)).AnswerText;
                await Clients.Others.SendAsync("displayAnswer", correctAnswer);

                await Task.Delay(5000);
            }

            await Clients.Others.SendAsync("roundComplete", quizCategory);
        }
Esempio n. 25
0
        public async Task SubmitAnswer(QuizCategory quizCategory, int questionId, int answerId)
        {
            var categoryQuestions = Questions[quizCategory];
            var question          = categoryQuestions.FirstOrDefault(p => p.QuestionId.Equals(questionId));

            if (question.CorrectAnswerId.Equals(answerId))
            {
                lock (_users)
                {
                    var connectionID = Context.ConnectionId;
                    if (_users.TryGetValue(connectionID, out QuizUserModel userPoints))
                    {
                        userPoints.Points += 1;
                    }
                }

                await RetrieveScores();
            }
        }
Esempio n. 26
0
        public List <Quiz> GetQuizCategory(List <Quiz> UnsortedList, QuizCategory category)
        {//Function to return list of quiz questions based off of category selected by user
            List <Quiz> Categorical = new List <Quiz>();

            if (category == QuizCategory.All)
            {
                Categorical = UnsortedList;
            }
            else
            {
                foreach (Quiz quiz in UnsortedList)
                {
                    if (quiz.Category == category)
                    {
                        Categorical.Add(quiz);
                    }
                }
            }
            return(Categorical);
        }
    public int GetMaximumPossibleScoreInCategory(QuizCategory category)
    {
        if (!CollectionExtensions.IsNullOrEmpty(questions))
        {
            // Get the questions with this type
            IEnumerable <QuizQuestion> questions = GetQuestionsWithCategory(category);
            // Initialize the max score
            int maxScore = 0;
            foreach (QuizQuestion q in questions)
            {
                maxScore += q.MaxPossibleScore;
            }

            return(maxScore);
        }
        else
        {
            return(0);
        }
    }
        public QuizCategory GetQuizCategory(QuizCategoryViewModel quizCategoryViewModel, bool withId = false)
        {
            var quizCategory = new QuizCategory
            {
                IconInButtonName = GetFileName(quizCategoryViewModel.IconInButtonFile),
                IconInPartyName  = GetFileName(quizCategoryViewModel.IconInPartyFile),
                TitleInEnglish   = quizCategoryViewModel.TitleInEnglish,
                TitleInFrench    = quizCategoryViewModel.TitleInFrench,
                TitleInGerman    = quizCategoryViewModel.TitleInGerman,
                TitleInItalian   = quizCategoryViewModel.TitleInItalian,
                TitleInSpain     = quizCategoryViewModel.TitleInSpain,
                GameId           = quizCategoryViewModel.GameId
            };

            if (withId)
            {
                quizCategory.Id = quizCategoryViewModel.Id;
            }
            return(quizCategory);
        }
        public QuizCategoryViewModel GetQuizCategoryViewModel(QuizCategory quizCategory, bool withId = false)
        {
            if (quizCategory == null)
            {
                return(null);
            }
            var quizCategoryViewModel = new QuizCategoryViewModel
            {
                TitleInEnglish = quizCategory.TitleInEnglish,
                TitleInFrench  = quizCategory.TitleInFrench,
                TitleInGerman  = quizCategory.TitleInGerman,
                TitleInItalian = quizCategory.TitleInItalian,
                TitleInSpain   = quizCategory.TitleInSpain,
                GameId         = quizCategory.GameId
            };

            if (withId)
            {
                quizCategoryViewModel.Id = quizCategory.Id;
            }
            return(quizCategoryViewModel);
        }
Esempio n. 30
0
        public static async Task <int?> GetCategoryIdAsync(string category)
        {
            if (string.IsNullOrWhiteSpace(category))
            {
                throw new ArgumentException("Category missing!", nameof(category));
            }

            category = category.ToLowerInvariant();

            IReadOnlyList <QuizCategory> categories = await GetCategoriesAsync().ConfigureAwait(false);

            QuizCategory result = categories
                                  ?.OrderBy(c => category.LevenshteinDistance(c.Name.ToLowerInvariant()))
                                  .FirstOrDefault();

            if (result is null || category.LevenshteinDistance(result.Name.ToLowerInvariant()) > 2)
            {
                return(null);
            }

            return(result.Id);
        }
Esempio n. 31
0
        public Quiz(string quest, string googleSearchItem, string rightanswer, string wronganswer1, string wronganswer2, QuizCategory category)
        {
            Question         = quest;
            GoogleSearchItem = googleSearchItem;
            RightAnswer      = rightanswer;
            WrongAnswer1     = wronganswer1;
            WrongAnswer2     = wronganswer2;
            Category         = category;
            switch (category)
            {//Custom constructor which assigns the image to the object based off of the enum Category
            case QuizCategory.General_Knowledge:
                imageQuizID = Resource.Drawable.Generalknowledge;
                break;

            case QuizCategory.Geography:
                imageQuizID = Resource.Drawable.Geography;
                break;

            case QuizCategory.History:
                imageQuizID = Resource.Drawable.History;
                break;
            }
        }