public ActionResult Create(QuestionAnswerModel questionAnswer) { try { // TODO: Add insert logic here QuestionAnswer _questionAnswer = new QuestionAnswer(); _questionAnswer.Id = questionAnswer.Id; _questionAnswer.AnswerTitle = questionAnswer.AnswerTitle; _questionAnswer.AnswerDescription = questionAnswer.AnswerDescription; _questionAnswer.AnswerCommentId = questionAnswer.AnswerCommentId; _questionAnswer.AnswerStatusId = questionAnswer.AnswerStatusId; _questionAnswer.CreatedBy = "Admin"; _questionAnswer.FromUserId = 1; _questionAnswer.IsActive = true; _questionAnswer.ParentAnswerId = questionAnswer.ParentAnswerId; _questionAnswer.Published = true; _questionAnswer.CreatedDate = DateTime.Now.ToUniversalTime(); _questionAnswer.ToUserId = 1; _questionAnswer.QuestionId = questionAnswer.QuestionId; QuestionAnswerBAL _questionAnswerBAL = new QuestionAnswerBAL(); _questionAnswerBAL.AddQuestionAnswer(_questionAnswer); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, QuestionAnswerModel questionAnswer) { try { // TODO: Add update logic here QuestionAnswerBAL _QuestionAnswerBAL = new QuestionAnswerBAL(); QuestionAnswer _questionAnswer = _QuestionAnswerBAL.GetQuestionAnswerById(id); _questionAnswer.Id = questionAnswer.Id; _questionAnswer.AnswerTitle = questionAnswer.AnswerTitle; _questionAnswer.AnswerDescription = questionAnswer.AnswerDescription; _questionAnswer.AnswerCommentId = questionAnswer.AnswerCommentId; _questionAnswer.AnswerStatusId = questionAnswer.AnswerStatusId; _questionAnswer.IsActive = questionAnswer.IsActive; _questionAnswer.ParentAnswerId = questionAnswer.ParentAnswerId; _questionAnswer.Published = questionAnswer.Published; _questionAnswer.QuestionId = questionAnswer.QuestionId; _questionAnswer.ToUserId = questionAnswer.ToUserId; _questionAnswer.UpdatedBy = "Admin"; _questionAnswer.UpdatedDate = DateTime.Now.ToUniversalTime(); _questionAnswer.FromUserId = questionAnswer.FromUserId; _QuestionAnswerBAL.UpdateQuestionAnswer(_questionAnswer); return(RedirectToAction("Index")); } catch { return(View()); } }
// // GET: /QuestoinAnswers/ public ActionResult Index() { QuestionAnswerBAL _questionAnswerBAL = new QuestionAnswerBAL(); List <QuestionAnswer> QAList = _questionAnswerBAL.GetAllQuestionAnswer(); List <QuestionAnswerModel> _QAModel = new List <QuestionAnswerModel>(); foreach (var q in QAList) { var model = new QuestionAnswerModel(); model.Id = q.Id; model.AnswerTitle = q.AnswerTitle; model.AnswerDescription = q.AnswerDescription; model.AnswerCommentId = q.AnswerCommentId; model.AnswerStatusId = q.AnswerStatusId; model.CreatedBy = "Admin"; model.FromUserId = 1; model.IsActive = q.IsActive; model.ParentAnswerId = 2; model.QuestionId = 1; model.ToUserId = 1; model.Published = true; model.CreatedDate = DateTime.Now.ToUniversalTime(); model.UpdatedBy = q.UpdatedBy; model.UpdatedDate = q.UpdatedDate; _QAModel.Add(model); } return(View(_QAModel)); }
public async Task <bool> Update(QuestionAnswerModel model) { var question = await _context.QuestionAnswers .Where(x => x.Id == model.Id).FirstOrDefaultAsync(); if (question.FileId > 0) { var file = await _context.StaticMedias.FindAsync(question.FileId); _context.StaticMedias.Remove(file); } if (question != null) { question.Id = model.Id; question.NoticeBoardId = model.NoticeBoardId; question.QuestionHint1 = model.QuestionHint1; question.QuestionHint2 = model.QuestionHint2; question.QuestionHint3 = model.QuestionHint3; question.Answer = model.Answer; question.File = new StaticMedia { ContentLength = model.File.ContentLength, ContentType = model.File.ContentType, FileName = model.File.FileName, InputStream = model.FileInputStream }; } await _context.SaveChangesAsync(); return(true); }
public async Task <bool> InsertStudentQuestions(QuestionAnswerModel model, long userId) { var question = new QuestionAnswer(); if (model.Id > 0) { question = await _context.QuestionAnswers.FindAsync(model.Id); } question.NoticeBoardId = model.NoticeBoardId; question.QuestionHint1 = model.QuestionHint1; question.QuestionHint2 = model.QuestionHint2; question.QuestionHint3 = model.QuestionHint3; question.Answer = model.Answer; if (model.Id == 0) { _context.QuestionAnswers.Add(question); await _context.SaveChangesAsync(); var student_question = new Data.Entities.StudentQuestions { QuestionId = question.Id, UserId = userId }; _context.StudentQuestions.Add(student_question); } await _context.SaveChangesAsync(); return(true); }
public async Task <ActionResult> Add() { var model = new QuestionAnswerModel(); model.NoticeBoards = await _noticeRepository.GetNoticeSelectList(); return(View(model)); }
public async Task <bool> Insert(QuestionAnswerModel model) { var question = new Data.Entities.QuestionAnswer { NoticeBoardId = model.NoticeBoardId, QuestionHint1 = model.QuestionHint1, QuestionHint2 = model.QuestionHint2, QuestionHint3 = model.QuestionHint3, Answer = model.Answer }; question.File = new StaticMedia { ContentLength = model.File.ContentLength, ContentType = model.File.ContentType, FileName = model.File.FileName, InputStream = model.FileInputStream }; _context.QuestionAnswers.Add(question); await _context.SaveChangesAsync(); return(true); }
public async Task <ActionResult> Index(QuestionAnswerModel model) { await _questionAnswerRepository.InsertStudentQuestions(model, LoggedInUserId); if (model.Id > 0) { return(RedirectToAction("Index", "PendingQueries", new { area = "Student" })); } model = new QuestionAnswerModel(); model.NoticeBoards = await _noticeBoardRepository.GetNoticeSelectList(); ViewBag.Message = "Query submitted successfully! Very soon you will receive answer of your query."; return(View(model)); }
private QuestionAnswerModel GetNextQA() { QuestionAnswerModel qa = new QuestionAnswerModel(); var lho = GetOperand(); var rho = GetOperand(); var op = GetOperator(); switch (op) { case "+": { var result = lho + rho; if ((result = AdjustResult(result)) != (lho + rho)) { qa.IsCorrect = false; } qa.Question = string.Format("{0}+{1}={2}", lho, rho, result); } break; case "-": { var result = lho - rho; if ((result = AdjustResult(result)) != (lho - rho)) { qa.IsCorrect = false; } qa.Question = string.Format("{0}-{1}={2}", lho, rho, result); } break; case "*": { var result = lho * rho; if ((result = AdjustResult(result)) != (lho * rho)) { qa.IsCorrect = false; } qa.Question = string.Format("{0}*{1}={2}", lho, rho, result); } break; } return(qa); }
public async Task <ActionResult> Add(QuestionAnswerModel model) { var uploadedFile = new byte[model.File.InputStream.Length]; model.File.InputStream.Read(uploadedFile, 0, uploadedFile.Length); model.FileInputStream = uploadedFile; if (model.Id > 0) { await _questionsRepository.Update(model); } else { await _questionsRepository.Insert(model); } return(RedirectToAction("Index")); }
public async Task <List <QuestionAnswerModel> > GetQuestionAnswersByIdArea(string strArea) { List <QuestionAnswerModel> questionAnswerModel = new List <QuestionAnswerModel>(); using (var _dbContext = new DataBaseContext()) { object[] parameters = new object[] { strArea }; var dReader = await _dbContext.ExecuteReaderAsync("sp_GetQuestionAnswerByArea", parameters); while (dReader.Read()) { var question = new QuestionAnswerModel(); question.id = 0; question.answer = dReader.GetString(1); question.source = "Editorial"; question.questions = dReader.GetString(0).Split(';'); question.metadata = new string[0]; questionAnswerModel.Add(question); } } return(questionAnswerModel); }
private async Task PostQuestionAnswer(QuestionAnswerModel answer, CancellationToken cancellationToken) { var response = await _httpClient.PostAsJsonAsync <QuestionAnswerModel>($"questions/answer", answer, cancellationToken); if (response.IsSuccessStatusCode) { return; } else if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.Forbidden) { throw new UnauthorizedAccessException(response.ReasonPhrase); } else if (response.StatusCode == HttpStatusCode.BadRequest) { return; } else { throw new Exception(response.ReasonPhrase); } }
// // GET: /QuestoinAnswers/Edit/5 public ActionResult Edit(int id) { QuestionAnswerBAL _QuestionAnswerBAL = new QuestionAnswerBAL(); QuestionAnswer _questionAnswer = _QuestionAnswerBAL.GetQuestionAnswerById(id); var model = new QuestionAnswerModel(); model.Id = _questionAnswer.Id; model.AnswerTitle = _questionAnswer.AnswerTitle; model.AnswerDescription = _questionAnswer.AnswerDescription; model.AnswerCommentId = _questionAnswer.AnswerCommentId; model.AnswerStatusId = _questionAnswer.AnswerStatusId; model.FromUserId = _questionAnswer.FromUserId; model.IsActive = _questionAnswer.IsActive; model.QuestionId = _questionAnswer.QuestionId; model.ToUserId = _questionAnswer.ToUserId; model.UpdatedBy = "Admin"; model.UpdatedDate = DateTime.Now.ToUniversalTime(); model.Published = _questionAnswer.Published; model.ParentAnswerId = _questionAnswer.ParentAnswerId; _QuestionAnswerBAL.UpdateQuestionAnswer(_questionAnswer); return(View(model)); }
public async Task <ActionResult> Add(QuestionAnswerModel model) { await _questionsRepository.Update(model); return(RedirectToAction("Index")); }
public QuestionForm(MyContext context) { _listQuestions = new List <QuestionModel>(); ///context.Questions ///.Select(x => new QuestionModel ///{ /// Text = x.Text, /// Answers = x.Answers.Select(y => new QuestionAnswerModel /// { /// Text=y.Text, /// IsTrue=y.IsTrue /// }).ToList() ///}).ToList(); foreach (var item in context.Questions.ToList()) { QuestionModel question = new QuestionModel { Text = item.Text, Answers = new List <QuestionAnswerModel>() }; foreach (var answer in context.Answers .Where(x => x.QuestionId == item.Id)) { var answerModel = new QuestionAnswerModel { Text = answer.Text, IsTrue = answer.IsTrue }; question.Answers.Add(answerModel); } _listQuestions.Add(question); } ///_listQuestions = new List<QuestionModel> ///{ /// new QuestionModel /// { /// Text = "Коли Гагарін призимлився перший раз?", /// Answers = new List<QuestionAnswerModel> /// { /// new QuestionAnswerModel /// { /// Text = "23 жовтня 2003р.", /// IsTrue = false /// }, /// new QuestionAnswerModel /// { /// Text = "1 вересня 1973р.", /// IsTrue = false /// }, /// new QuestionAnswerModel /// { /// Text = "30 лютого 1961р.", /// IsTrue = false /// }, /// new QuestionAnswerModel /// { /// Text = "12 квітня 1961р.", /// IsTrue = true /// }, /// } /// }, /// new QuestionModel /// { /// Text = "Коли родився Шевченко?", /// Answers = new List<QuestionAnswerModel> /// { /// new QuestionAnswerModel /// { /// Text = "23 жовтня 1894р.", /// IsTrue = false /// }, /// new QuestionAnswerModel /// { /// Text = "1 вересня 1973р.", /// IsTrue = false /// }, /// new QuestionAnswerModel /// { /// Text = "9 березня 1814р.", /// IsTrue = true /// }, /// new QuestionAnswerModel /// { /// Text = "12 квітня 1961р.", /// IsTrue = false /// }, /// } /// } ///}; InitializeComponent(); result = new bool[_listQuestions.Count]; }
public AnswerQuestionAction(int trackId, QuestionAnswerModel answer) { Answer = answer; TrackId = trackId; }