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);
        }
Exemple #2
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);
        }
Exemple #3
0
        public QuizCategoryViewModel GetQuizCategoryViewModel()
        {
            QuizCategoryViewModel quizVM = new QuizCategoryViewModel();

            quizVM.ListCategory = (from category in context.Categories
                                   select new SelectListItem
            {
                Text = category.CategoryName,
                Value = category.CategoryId.ToString()
            }).ToList();
            return(quizVM);
        }
Exemple #4
0
        // GET: Quiz
        public ActionResult Index()
        {
            QuizCategoryViewModel objcategoryViewModel = new QuizCategoryViewModel();

            objcategoryViewModel.ListofCategory = (from objCat in obQuizDbEntities.Catagories
                                                   select new SelectListItem()
            {
                Value = objCat.CategoryId.ToString(),
                Text = objCat.CategoryName.ToString()
            }).ToList();

            return(View(objcategoryViewModel));
        }
 public async Task <IActionResult> Edit(int id, QuizCategoryViewModel model)
 {
     if (id != model.Id)
     {
         return(NotFound());
     }
     ModelState.Remove("IconInButtonFile");
     ModelState.Remove("IconInPartyFile");
     if (ModelState.IsValid)
     {
         try
         {
             _quizCategoryService.BeginTransaction();
             var quizCategory = _quizCategoryService.Get(x => x.Id == model.Id);
             if (quizCategory != null)
             {
                 model.GameId = quizCategory.GameId;
                 quizCategory.TitleInEnglish = model.TitleInEnglish;
                 quizCategory.TitleInFrench  = model.TitleInFrench;
                 quizCategory.TitleInGerman  = model.TitleInGerman;
                 quizCategory.TitleInItalian = model.TitleInItalian;
                 quizCategory.TitleInSpain   = model.TitleInSpain;
                 if (model.IconInButtonFile != null)
                 {
                     quizCategory.IconInButtonName = helper.GetFileName(model.IconInButtonFile);
                     await helper.FileUploadAsync(model.IconInButtonFile, quizCategory.IconInButtonName, "QuizCategory");
                 }
                 if (model.IconInPartyFile != null)
                 {
                     quizCategory.IconInButtonName = helper.GetFileName(model.IconInPartyFile);
                     await helper.FileUploadAsync(model.IconInPartyFile, quizCategory.IconInButtonName, "QuizCategory");
                 }
                 _quizCategoryService.Update(quizCategory);
                 _quizCategoryService.CommitTransaction();
             }
         }
         catch (DbUpdateConcurrencyException)
         {
             _quizCategoryService.RollbackTransaction();
             if (!QuizCategoryExists(model.Id))
             {
                 return(NotFound());
             }
         }
         return(RedirectToAction(nameof(Index), new { id = model.GameId }));
     }
     return(View(model));
 }
        public ActionResult QuizStudent()
        {
            int sID = Convert.ToInt32(Session["StudentId"]);
            QuizCategoryViewModel objQuizViewModel = new QuizCategoryViewModel();

            objQuizViewModel.ListofCategory = (from objcat in db.Categories

                                               join objfrndlist in db.FriendListForStudnets on objcat.CategoryTeacher equals objfrndlist.teacherid
                                               where objfrndlist.studentid == sID && objfrndlist.friendlist == 1 && objcat.available == 1
                                               select new SelectListItem()
            {
                Value = objcat.CategoryId.ToString(),
                Text = objcat.CategoryName
            }).ToList();



            return(View(objQuizViewModel));
        }
        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 ActionResult GetFinalResult(QuizCategoryViewModel quizCategoryViewModel)
        {
            int    total         = Convert.ToInt32(Session["total"]);
            string candidateName = quizCategoryViewModel.CandidateName;
            int    categotyId    = quizCategoryViewModel.CategoryId;


            ResultModel objresultModel = new ResultModel();

            objresultModel.listOfcandidateAnswers = (from obj in objquizdbEntities.Results
                                                     where obj.UserId == candidateName
                                                     select new CanAnswer()
            {
                AnswerText = obj.AnswerText,
                QuestionId = obj.QuestionId,
            }).ToList();



            var UserResult = (from objResult in objresultModel.listOfcandidateAnswers
                              join objAnswer in objquizdbEntities.Answers on objResult.QuestionId equals objAnswer.QuestionId
                              join objQuestion in objquizdbEntities.Questions on objResult.QuestionId equals objQuestion.QuestionId

                              select new ResultModel()
            {
                Question = objQuestion.QuestionName,
                Answer = objAnswer.Answertext,
                AnswerByUser = objResult.AnswerText,
                Status = objAnswer.Answertext == objResult.AnswerText ? "Correct" : "Wrong",
                total = objAnswer.Answertext == objResult.AnswerText ? total = total + 1 : total,
            }).ToList();

            Session["total"] = total;
            Session.Abandon();



            return(View(UserResult));
        }
        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);
        }
        public async Task <IActionResult> Create(QuizCategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _quizCategoryService.BeginTransaction();
                    var quizCategory = helper.GetQuizCategory(model);
                    quizCategory.Id = _quizCategoryService.Add(quizCategory);
                    await helper.FileUploadAsync(model.IconInButtonFile, quizCategory.IconInButtonName, "QuizCategory");

                    await helper.FileUploadAsync(model.IconInPartyFile, quizCategory.IconInPartyName, "QuizCategory");

                    _quizCategoryService.CommitTransaction();
                    return(RedirectToAction(nameof(Index), new { id = model.GameId }));
                }
                catch
                {
                    _quizCategoryService.RollbackTransaction();
                }
            }
            return(View(model));
        }