private static void FillQuizzes(QuizRepository quizzes) { quizzes.CreateQuiz ( "Test quiz", QuestionFactory.Create("Some question 1?", ChoiceFactory.Create("Meh 1", 0), ChoiceFactory.Create("Kinda 1", 5), ChoiceFactory.Create("Yes 1!", 10)), QuestionFactory.Create("Some question 2?", ChoiceFactory.Create("Meh 2", 0), ChoiceFactory.Create("Kinda 2", 5), ChoiceFactory.Create("Yes 2!", 10)), QuestionFactory.Create("Some question 3?", ChoiceFactory.Create("Meh 3", 0), ChoiceFactory.Create("Kinda 3", 5), ChoiceFactory.Create("Yes 3!", 10)) ); quizzes.CreateQuiz ( "Test quiz 2", QuestionFactory.Create("Some question 1?", ChoiceFactory.Create("Meh 1", 0), ChoiceFactory.Create("Kinda 1", 5), ChoiceFactory.Create("Yes 1!", 10)), QuestionFactory.Create("Some question 2?", ChoiceFactory.Create("Meh 2", 0), ChoiceFactory.Create("Kinda 2", 5), ChoiceFactory.Create("Yes 2!", 10)), QuestionFactory.Create("Some question 3?", ChoiceFactory.Create("Meh 3", 0), ChoiceFactory.Create("Kinda 3", 5), ChoiceFactory.Create("Yes 3!", 10)) ); }
public async Task <IActionResult> AddQuiz(NewQuizViewModel quizBodyData) { int currentUserId = User.Claims.GetUserId(); IActionResult imageHttpResponse = FileValidityChecker(quizBodyData); if (IActionResult.Equals(imageHttpResponse, Ok())) { return(imageHttpResponse); } string fileUrl; AzureBlobService blobService; try { blobService = new AzureBlobService(); await blobService.InitializeBlob(); fileUrl = await blobService.UploadPhoto(quizBodyData.Files[0]); } catch (Exception) { return(BadRequest("Image could not be uploaded.")); } Quiz createdQuiz = quizRepository.CreateQuiz(new Quiz { Title = quizBodyData.Title, PictureUrl = fileUrl, UserId = currentUserId }); if (createdQuiz == null) { return(BadRequest("Quiz couldn't be created")); } QuizViewModel quizVm = entityToVmMapper.Map(createdQuiz); quizVm.PictureUrl = blobService.urlPath.AbsoluteUri.ToString() + "users/" + fileUrl; return(Ok(new { quizVm.Id, quizVm.Title, quizVm.PictureUrl })); }
public ActionResult AddQuiz(TblQuiz objQuiz, string submit) { JavaScriptSerializer json_serializer = new JavaScriptSerializer(); json_serializer.MaxJsonLength = int.MaxValue; object[] objTblQue = (object[])json_serializer.DeserializeObject(objQuiz.hdnData); objQuiz.questionObject = objTblQue; try { if (ModelState.IsValid) { TblUser sessionUser = (TblUser)Session["UserSession"]; if (sessionUser != null) { objQuiz.TenantId = sessionUser.TenantId; int rows = 0; if (objQuiz.QuizId == 0) { rows = quizRepository.CreateQuiz(objQuiz); } else { rows = quizRepository.UpdateQuiz(objQuiz); } if (rows > 0) { TempData["QuizMessage"] = "Quiz Saved Successfully"; if (submit == "Exit") { return(View("AuthorContent", objQuiz)); } if (submit == "Save") { return(CreateScormCourse(objQuiz, rows)); } //return RedirectToAction("Index"); //if (submit == "Save") //{ // return RedirectToAction("EditQuiz", new { id = rows }); //} } else if (rows == 0) { TempData["ErrorMessage"] = "There is some problem while saving Quiz"; return(View("AuthorContent", objQuiz)); } else if (rows == -2) { TempData["ErrorMessage"] = "Quiz Not Saved"; return(View("AuthorContent", objQuiz)); } else { return(View("AuthorContent", objQuiz)); } } } return(View("AuthorContent", objQuiz)); } catch (Exception ex) { //newException.AddDummyException("11111"); newException.AddException(ex); return(View("AuthorContent")); } }