public IActionResult Index(NewQuestionModel model) { var storyaddDto = new StoryAddDto() { Description = DateTime.Now.ToString(), Link = model.StoryLink, Title = model.StoryTitle, }; _storyService.Add(storyaddDto); ViewData["message"] = "Sınav Başarıyla Oluşturuldu !"; var lastindex = _storyService.LastIndex(storyaddDto); var question1 = new QuestionAddDto() { StoryId = lastindex, CorrectOption = model.Question1.CorrectOption, OptionA = model.Question1.OptionA, OptionB = model.Question1.OptionB, OptionC = model.Question1.OptionC, OptionD = model.Question1.OptionD, Title = model.Question1.Title }; var question2 = new QuestionAddDto() { StoryId = lastindex, CorrectOption = model.Question2.CorrectOption, OptionA = model.Question2.OptionA, OptionB = model.Question2.OptionB, OptionC = model.Question2.OptionC, OptionD = model.Question2.OptionD, Title = model.Question2.Title }; var question3 = new QuestionAddDto() { StoryId = lastindex, CorrectOption = model.Question3.CorrectOption, OptionA = model.Question3.OptionA, OptionB = model.Question3.OptionB, OptionC = model.Question3.OptionC, OptionD = model.Question3.OptionD, Title = model.Question3.Title }; var question4 = new QuestionAddDto() { StoryId = lastindex, CorrectOption = model.Question4.CorrectOption, OptionA = model.Question4.OptionA, OptionB = model.Question4.OptionB, OptionC = model.Question4.OptionC, OptionD = model.Question4.OptionD, Title = model.Question4.Title }; _questionService.Add(question1); _questionService.Add(question2); _questionService.Add(question3); _questionService.Add(question4); return(RedirectToAction("Index")); }
//[Authorize(Roles = "canEdit")] public ActionResult Create([Bind(Include = "idQuestion,description,rep1,rep2,rep3,correctAnswer")] Question question) { if (ModelState.IsValid) { questionService.Add(question); questionService.Commit(); return(RedirectToAction("Index")); } return(View(question)); }
public void CreateTemplate(TemplateModel model) { var template = new Template() { Content = model.Content, Duration = model.Duration, Level = model.Level, PassScore = model.PassScore, Skill = model.Skill }; var newTemplate = _TemplateService.Add(template); foreach (var item in model.Questions) { var question = new Question() { Content = item.Content, TemplateId = newTemplate.ID }; var newQuestion = _QuestionService.Add(question); var listAnswer = new List <Answer>(); foreach (var ans in item.Answers) { var answer = new Answer() { QuestionId = newQuestion.ID, Content = ans.Content, IsCorrect = ans.IsCorrect }; listAnswer.Add(answer); } _AnswerService.Add(listAnswer); } }
public ActionResult Detail(Question model, HttpPostedFileBase fileInput) { if (ModelState.IsValid) { try { if (fileInput.ContentLength > 0) { string _fileName = Path.GetFileName(fileInput.FileName); bool exists = System.IO.Directory.Exists(Server.MapPath("~/FileAttach")); if (!exists) { Directory.CreateDirectory(Server.MapPath("~/FileAttach")); } string _path = Path.Combine(Server.MapPath("~/FileAttach"), _fileName); fileInput.SaveAs(_path); model.attachment = _fileName; } } catch (Exception ex) { } MvcCaptcha.ResetCaptcha("ExampleCaptcha"); model.createTime = DateTime.Now; _Service.Add(model); _Service.Save(); return(Content("<script language='javascript' type='text/javascript'>alert('Câu hỏi đã được gửi đi thành công!');window.location = '/hoi-dap';</script>")); } return(View(model)); }
public ActionResult SurveyQuestionCreate(SurveyViewModel surveyViewModel, SurveyQuestionCreateViewModel surveyQuestionCreateViewModel) { var model = new SurveyQuestionCreateViewModel(); var personId = HttpContext.Session.GetInt32("personId"); if (surveyViewModel.Survey != null) { surveyViewModel.Survey.StartDate = DateTime.Now; surveyViewModel.Survey.EndDate = DateTime.Now; surveyViewModel.Survey.ManagerId = (int)personId;//şuanlık //personId surveyViewModel.Survey.IsOpen = true; _surveyService.Add(surveyViewModel.Survey); } if (surveyQuestionCreateViewModel.Question == null) { model.SurveyId = surveyViewModel.Survey.Id; model.Questions = _questionService.GetBySurveyId(surveyViewModel.Survey.Id); model.QuestionResponseOptions = _questionOptionService.GetAll(); } else { surveyQuestionCreateViewModel.Question.QuestionTypeId = 1; //Soru türü için surveyQuestionCreateViewModel.Question.SurveyId = surveyQuestionCreateViewModel.SurveyId; _questionService.Add(surveyQuestionCreateViewModel.Question); model.SurveyId = surveyQuestionCreateViewModel.SurveyId; model.Questions = _questionService.GetBySurveyId(surveyQuestionCreateViewModel.SurveyId); model.QuestionResponseOptions = _questionOptionService.GetAll(); } return(View(model)); }
public ActionResult Add(string titre, string contenu, HttpPostedFileBase attachment) { string path = ""; var extension = Path.GetExtension(attachment.FileName); if (attachment != null && attachment.ContentLength > 0) { if (extension.ToLower().Equals(".png") || extension.ToLower().Equals(".jpg") || extension.ToLower().Equals(".jpeg")) { attachment.SaveAs(Path.Combine(Server.MapPath("~/Resources/Documents"), Path.GetFileName(attachment.FileName))); path = "~/Resources/Questions/" + Path.GetFileName(attachment.FileName); } } Question question = new Question { Titre = titre, Contenu = contenu, Attachment = path, DateQuestion = DateTime.Now, EtudiantId = ((Etudiant)Session["user"]).EtudiantId }; question = _questionService.Add(question); if (question == null) { throw new HttpException(500, "Votre Question a rencontre un probleme"); } return(RedirectToAction("Index", "Discussion")); }
public async Task <ActionResult> AddQuestionAsync(Question question) { if (question != null) { var answer = question.Answers.FirstOrDefault(); if (answer != null) { answer.Id = Guid.NewGuid().ToString(); answer.Date = DateTime.Now; answer.SenderName = User.Identity.Name; answer.IsAdmin = _userService.IsAdmin(_userService.GetUserBySystemName(User)); } question.CreateDate = DateTime.Today; _questionService.Add(question); await _hubContext.Clients.Group(AppUserDefaults.AdministratorsRoleName).AddQuestionChange(question); await _hubContext.Clients.Group(question.Id).AddQuestionChange(question); return(new JsonResult(new { Id = question.Id, Title = question.Title, AnswerCount = question.Answers.Count() })); } return(new JsonResult(null)); }
public JsonResult QuestionEdit(int QuestionId, QuestionModel QuestionModel) { try { if (QuestionId == 0) { Core3Base.Infra.Data.Entity.Question Question = new Core3Base.Infra.Data.Entity.Question { Content = QuestionModel.Question.Content, IsActive = QuestionModel.Question.IsActive, }; return(Json(_QuestionService.Add(Question).HttpGetResponse())); } else { var Question = _QuestionService.GetQuestionById(QuestionId).Result; Question.Content = QuestionModel.Question.Content; Question.IsActive = QuestionModel.Question.IsActive; return(Json(_QuestionService.Update(Question).HttpGetResponse())); } } catch (Exception e) { return(Json(e.Message)); } }
public ActionResult Create([Bind(Include = "QuestionTypeId,Name,MultipleAnswer")] QuestionVM questionVM) { try { if (ModelState.IsValid) { QuestionDTO questionDTO = Mapper.Map <QuestionDTO>(questionVM); //int questionId = QuestionService.AddAndGetId(questionDTO); QuestionService.Add(questionDTO); return(RedirectToAction("Index")); } ViewBag.QuestionTypeId = GetQuestionTypeIdSelectList(questionVM.QuestionTypeId); return(View(questionVM)); } catch (UniqueConstraintException ex) { return(Json(new { hasError = true, data = ex.Message }, JsonRequestBehavior.AllowGet)); } }
private void AddNewQuestion(QuestionModel questionModel, IQuestionService questionService, AnswerModel answerModel, IAnswerService answerService) { //* adding a question questionModel.isOpen = false; questionService.Add(questionModel); //* adding answers answerModel.QuestionID = questionService.GetAll().OrderByDescending(x => x.QuestionID).First().QuestionID; string[] answerText = new string[] { txt_correctAnswer.Text, txt_secondAnswer.Text, txt_thirdAnswer.Text, txt_fourthAnswer.Text }; foreach (var item in answerText) { if (item == txt_correctAnswer.Text) { answerModel.isCorrect = true; answerModel.AnswerText = item; answerService.Add(answerModel); } else { answerModel.isCorrect = false; answerModel.AnswerText = item; answerService.Add(answerModel); } } }
public ActionResult Create([Bind("CategoryId,Title,Description,SelectedTags")] QuestionModel questionModel) { var m = new QuestionModel(); LoadCreate(m); if (ModelState.IsValid) { try { _unitOfWork.BeginTransactionAnsyc(); var question = new Question(AuthorVerify().Id, questionModel.CategoryId, questionModel.Title, questionModel.Description); _questionService.Add(question); var questionTags = new List <QuestionTag>(); foreach (var tag in JsonConvert.DeserializeObject <List <TagModel> >(questionModel.SelectedTags)) { if (tag.Id.HasValue) { questionTags.Add(new QuestionTag() { QuestionId = question.Id, TagId = (int)tag.Id }); } else { var newTag = new Tag() { Name = tag.Value }; _tagService.Add(newTag); questionTags.Add(new QuestionTag() { QuestionId = question.Id, TagId = newTag.Id }); } } question.QuestionTags = questionTags; _unitOfWork.SaveChanges(); _unitOfWork.Commit(); return(RedirectToAction(nameof(Index))); } catch (Exception e) { _unitOfWork.RollbackTransaction(); return(View(m)); } } else { return(View(m)); } }
public ActionResult Create(Question question) { if (_questionService.Add(question)) { return(View("Index")); } return(View("Index")); }
public async Task <IActionResult> Create(string question) { Question question1 = new Question(); question1.Content = question; await _questionService.Add(question1); return(RedirectToAction("Index")); }
public IActionResult Create([FromBody] Question question) { if (!ModelState.IsValid) { return(BadRequest()); } _service.Add(question); return(Ok(question)); }
public IActionResult AddQuestion(Question question) { var result = _questionService.Add(question); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public ActionResult Create(Question question) { if (ModelState.IsValid) { _questionService.Add(question); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(_categoryService.GetAll(), "Id", "Name", question.CategoryId); return(View(question)); }
public IActionResult Create(QuestionDto questionDto, string userId) { if (userId == null) { userId = User.FindFirstValue(ClaimTypes.NameIdentifier); } string questionUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); _questionService.Add(questionDto, userId, questionUserId); return(LocalRedirect($"~/question/page?userId={userId}")); }
public IActionResult Add([FromBody] QuestionModel model) { try { return(Ok(_questionService.Add(model.ToDomainModel()).ToApiModel())); } catch (Exception e) { ModelState.AddModelError("QuestionAdd", e.Message); return(BadRequest(ModelState)); } }
public IActionResult Add(Question question) { try { return(Ok(_questionService.Add(question))); } catch (Exception) { ModelState.AddModelError("AddQuestion", "Not Implemented!"); return(NotFound(ModelState)); } }
public IActionResult Add([FromQuery] QuestionViewModel model) { var QuestionsResponse = _QuestionsService.Add(new Question { Content = model.Content }); if (QuestionsResponse.IsSucceeded && QuestionsResponse.Result != null) { return(Ok(QuestionsResponse.Result)); } return(QuestionsResponse.HttpGetResponse()); }
public IActionResult Add([FromBody] QuestionModel question) { // TODO: replace the following code with a complete implementation // that will add a new question try { return(Ok(_questionService.Add(question.ToDomainModel()))); } catch (Exception ex) { ModelState.AddModelError("AddQuestion", ex.Message); return(NotFound(ModelState)); } }
public IActionResult Add([FromBody] QuestionModel questionModel) { //ModelState.AddModelError("AddQuestion", "Not Implemented!"); //return NotFound(ModelState); try { var savedQuestion = _questionService.Add(questionModel.ToDomainModel()); return(CreatedAtAction("Get", new { Id = savedQuestion.Id }, savedQuestion.ToApiModel())); } catch (System.Exception ex) { ModelState.AddModelError("AddQuestion", ex.Message); return(BadRequest(ModelState)); } }
public ActionResult AddQuestions(QuestionModel question) { if (ModelState.IsValid) { Question que = _mappingService.Map <QuestionModel, Question>(question); que.QuestionDescription = HttpUtility.HtmlDecode(question.QuestionDescription); que.CorrectAnswer = setCorrectAnswer(question); que.Answer = HttpUtility.HtmlDecode(question.Answer); que.Tags = string.Join(",", question.SkillTag); que.IsPublishd = true; var userEmailId = User.Identity.Name; var user = _containerUserService.FindUserByEmail(userEmailId); bool isEdit = false; que.Status = QuestionStatus.ReadyForReview; if (question.Edit) { isEdit = true; que.ModifiedBy = user.ID; que.ModifiedOn = DateTime.Now; _questionService.Update(que); } else { que.CreatedOn = DateTime.Now; que.CreatedBy = user.ID; _questionService.Add(que); } var btnValue = Request["btnSaveAndAddNewQuestion"]; int success = 1; if (!string.IsNullOrWhiteSpace(btnValue) && btnValue.Equals("save & add another question", StringComparison.OrdinalIgnoreCase)) { success = 2; } question = new QuestionModel() { Success = success, Edit = isEdit, QuestionType = "0", SkillTagsList = Tags() }; } else { question = new QuestionModel { QuestionType = "0", SkillTagsList = Tags() }; } ModelState.Clear(); return(View(question)); }
public void Import(string fileName, string quizName) { var json = File.ReadAllText(fileName); var questions = JsonConvert.DeserializeObject <IEnumerable <JsonQuestion> >(json); var quizId = quizService.Add(quizName); foreach (var question in questions) { var questionId = questionService.Add(question.Question, quizId); foreach (var answer in question.Answers) { answerService.Add(answer.Answer, answer.Correct ? 1 : 0, answer.Correct, questionId); } } }
public async Task <object> AddQuestion([FromBody] Question question) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await _questionService.CheckIfExists(question) || !await _questionService.Validate(question)) { return(BadRequest()); } await _questionService.Add(question); return(question); }
public ActionResult Post([FromBody] Question question) { try { if (!ModelState.IsValid) { return(BadRequest()); } _questionService.Add(question); return(Ok()); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public IActionResult Question(QuestionViewModel model) { var question = new Question { Name = model.Question.Name, Lastname = model.Question.Lastname, CategoryId = model.Question.CategoryId, Mail = model.Question.Mail, QuestionContent = model.Question.QuestionContent, QuestionDate = DateTime.Now, QuestionSubject = model.Question.QuestionSubject, }; _questionService.Add(question); return(RedirectToAction("Index")); }
public IActionResult CreateQuestion(Question model) { try { if (ModelState.IsValid) { _questionService.Add(model); ViewBag.Msg = "Question Created Successfully"; } } catch { ViewBag.Msg = "Something went wrong"; } return(View()); }
public IActionResult CreateExam(ExamCreateModel model) { Exam exam = new Exam(); int d = Convert.ToInt32(model.Title); exam.ExamContent = model.Content; exam.ExamTitle = titles[d - 1].ToString(); exam.CreatedDate = DateTime.Now; _examService.Add(exam); int exam_id = exam.ExamId; for (int i = 0; i < 4; i++) { Question question = new Question(); question.ExamId = exam_id; question.QuestionContent = model.Questions[i].QuestionContent; _questionService.Add(question); question.ExamId = exam_id; int question_id = question.QuestionId; for (int j = 0; j < 4; j++) { Option option = new Option(); option.selection = model.Questions[i].Options[j].selection; option.QuestionId = question_id; string a = model.Questions[i].Answer.ToString().ToLower(); if (((model.Questions[i].Answer) - 65) == j) { option.IsCorrect = "true"; } else { option.IsCorrect = "false"; } _optionsService.Add(option); } } return(View("Index")); }
public async Task <IActionResult> Add([FromBody] QuestionModel model) { try { var response = await _service.Add(model); if (!response.IsSuccessful) { return(BadRequest(response)); } return(Ok(response)); } catch (Exception x) { _log.LogError(ExceptionLogger.ExceptionDetails(x)); return(StatusCode(500, "Internal Server Error.")); } }