public FileContentResult getImg(int id) { byte[] byteArray = QuestionRepository.Find(id).Image; return(byteArray != null ? new FileContentResult(byteArray, "image/jpeg") : null); }
public ActionResult AddAnswer(int id) { FillDropdownValues(); var model = QuestionRepository.Find(id); return(View(model)); }
public ActionResult AddImagePost(HttpPostedFileBase file, int id) { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/App_Data/images"), fileName); file.SaveAs(path); if (ModelState.IsValid) { var modelDb = QuestionRepository.Find(id); modelDb.Image = new byte[file.ContentLength]; file.InputStream.Read(modelDb.Image, 0, file.ContentLength); if (this.TryUpdateModel(modelDb)) { QuestionRepository.Update(modelDb); QuestionRepository.Save(); return(RedirectToAction("Index")); } } } return(View()); }
public Question Add(Question question) { using (IUnitOfWork unitOfWork = context.CreateUnitOfWork()) { if (questionRepo.Find(x => x.QuestionSort == question.QuestionSort && x.PeriodId == question.PeriodId).Any()) { throw new ArgumentException("Question in this sort position already exists.", nameof(question.QuestionSort)); } int newQuestionId = questionRepo.Insert(question); if (newQuestionId <= 0) { throw new FailedOperationException("Failed to insert Question.", question); } unitOfWork.SaveChanges(); return(questionRepo.GetById(newQuestionId)); } }
/// <summary> /// Gets the viewable questions. /// </summary> /// <param name="startDate">The start date.</param> /// <param name="endDate">The end date.</param> /// <param name="categoryId">The category id.</param> /// <returns>Viewable questions.</returns> public IEnumerable <Question> GetViewableQuestions(DateTime?startDate, DateTime?endDate, int?categoryId) { if (startDate == null || endDate == null) { return(QuestionRepository.Find(item => item.IsVisible == true && item.IsDeleted == false && item.CategoryId == categoryId)); } else { return(QuestionRepository.Find(item => item.CreationDate >= startDate && item.CreationDate <= endDate && item.IsDeleted == false && item.IsVisible == true && item.CategoryId == categoryId)); } }
public JsonResult DeleteQuestion(int id, int quizId) { var modelQuestion = QuestionRepository.Find(id); var modelQuiz = QuizRepository.Find(quizId); modelQuiz.Questions.Remove(modelQuestion); QuizRepository.Update(modelQuiz); QuizRepository.Save(); return(new JsonResult() { Data = "OK", JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public JsonResult DeleteAnswer(int id, int questionId) { var modelAnswer = AnswerRepository.Find(id); var modelQuestion = QuestionRepository.Find(questionId); modelQuestion.Answers.Remove(modelAnswer); QuestionRepository.Update(modelQuestion); QuestionRepository.Save(); return(new JsonResult() { Data = "OK", JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ActionResult AddAnswerPost(Question formModel, int Answer) { if (ModelState.IsValid) { var modelDb = QuestionRepository.Find(formModel.ID); var modelAnswer = AnswerRepository.Find(Answer); modelDb.Answers.Add(modelAnswer); if (this.TryUpdateModel(modelDb)) { QuestionRepository.Update(modelDb); QuestionRepository.Save(); //return RedirectToAction("Index"); } } FillDropdownValues(); return(View(formModel)); }
public ActionResult EditPost(Question formModel) { if (ModelState.IsValid) { var modelDb = QuestionRepository.Find(formModel.ID); if (this.TryUpdateModel(modelDb)) { QuestionRepository.Update(modelDb); QuestionRepository.Save(); return(RedirectToAction("Index")); } } FillDropdownValues(); return(View(formModel)); }
public ActionResult AddQuestionPost(Quiz formModel, int Question) { if (ModelState.IsValid) { var modelDb = QuizRepository.Find(formModel.ID); var modelQuestion = QuestionRepository.Find(Question); modelDb.Questions.Add(modelQuestion); if (this.TryUpdateModel(modelDb)) { QuizRepository.Update(modelDb); QuizRepository.Save(); //return RedirectToAction("Index"); } } FillDropdownValues(); return(View(formModel)); }
/// <summary> /// Gets the question. /// </summary> /// <param name="questionId">The question id.</param> /// <returns>Found question.</returns> public Question GetQuestion(int questionId) { return(QuestionRepository.Find(question => question.Id == questionId && question.IsDeleted == false).SingleOrDefault()); }
public ActionResult AddImage(int id) { var model = QuestionRepository.Find(id); return(View(model)); }
/// <summary> /// Gets the student questions. /// </summary> /// <param name="studentId">The student id.</param> /// <param name="startDate">The start date.</param> /// <param name="endDate">The end date.</param> /// <returns>Student questions.</returns> public IEnumerable <Question> GetStudentQuestions(Guid studentId, DateTime?startDate, DateTime?endDate) { return(QuestionRepository.Find(item => item.AuthorId == studentId && item.CreationDate >= startDate && item.CreationDate <= endDate && item.IsDeleted == false)); }
public ActionResult Details(int id) { var model = QuestionRepository.Find(id); return(View(model)); }
/// <summary> /// Gets all questions. /// </summary> /// <param name="startDate">The start date.</param> /// <param name="endDate">The end date.</param> /// <returns>All the questions.</returns> public IEnumerable <Question> GetAllQuestions(DateTime?startDate, DateTime?endDate) { return(QuestionRepository.Find(item => item.CreationDate >= startDate && item.CreationDate <= endDate && item.IsDeleted == false)); }
/// <summary> /// Gets the user questions. /// </summary> /// <param name="userId">The user id.</param> /// <returns>User questions.</returns> public IEnumerable <Question> GetUserQuestions(Guid userId) { return(QuestionRepository.Find(question => question.AuthorId == userId && question.IsDeleted == false)); }
public async Task <Question> Show(Guid id) { return(await _repo.Find(id)); }
/// <summary> /// Gets the questions. /// </summary> /// <param name="questionIds">The question ids.</param> /// <returns>The questions.</returns> public IEnumerable <Question> GetQuestions(IEnumerable <int> questionIds) { return(QuestionRepository.Find(item => questionIds.Contains(item.Id) && item.IsDeleted == false)); }