public static question QuestionToDAL(QuestionDTO ques) { return(new question() { question_id = ques.question_id, question_text = ques.question_text, sub_category_id = ques.sub_category_id, question_level = ques.level, type_id = ques.type_id, }); }
} // Default constructor public Question(QuestionDTO questionDTO) { ID = questionDTO.ID; QuestionText = questionDTO.QuestionText; AnswerOne = questionDTO.AnswerOne; AnswerTwo = questionDTO.AnswerTwo; AnswerThree = questionDTO.AnswerThree; CorrectAnswer = questionDTO.CorrectAnswer; ImageUrl = questionDTO.ImageUrl; ChosenAnswer = questionDTO.ChosenAnswer; }
public Question MapperToEntity(QuestionDTO questionDTO) { var question = new Question { Id = questionDTO.Id, Description = questionDTO.Description, Views = questionDTO.Views }; return(question); }
public IActionResult UpdateQuestion(QuestionDTO questionDto) { try { _questionManagerService.UpdateQuestion(questionDto); return(Ok()); } catch (Exception e) { return(StatusCode(500, new { Message = "Server ERROR occured." })); } }
public JsonResult <IEnumerable <QuestionDTO> > GetSearch(string q) { var searchResult = db.Search(q); var en = searchResult.GetEnumerator(); List <QuestionDTO> results = new List <QuestionDTO>(); while (en.MoveNext()) { results.Add(QuestionDTO.FromEntity(en.Current)); } return(Json(results.AsEnumerable())); }
public IHttpActionResult AddRequirement(QuestionDTO question) { try { QuestionManager.AddRequirement(question); return(Ok()); } catch (Exception e) { return(BadRequest("system error" + e)); } }
public void AddItem(QuestionDTO questionDTO) { if (String.IsNullOrEmpty(questionDTO.Query)) { throw new ValidationException("Wrong or empty properties", "Query"); } var questionDAL = MapperBLL.Mapper.Map <Question>(questionDTO); uof.Questions.Create(questionDAL); uof.Save(); }
public ActionResult EditQuestion(int questionId) { ViewBag.Images = imageService.GetAll(); QuestionDTO question = questionService.GetById(questionId); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <QuestionDTO, ViewQuestionModel>()).CreateMapper(); ViewQuestionModel viewQuestionModel = mapper.Map <QuestionDTO, ViewQuestionModel>(question); ViewBag.QuestType = questService.GetById(question.QuestId).Type; ViewBag.User = userService.GetUserByEmail(User.Identity.Name); ViewBag.Id = question.QuestId; return(View(viewQuestionModel)); }
public IHttpActionResult GetQuestionByIndexAndTestId(int index, int testId) { QuestionDTO question = _questionService.GetQuestionByIndexAndTestId(index, testId); if (question == null) { return(Content(HttpStatusCode.NotFound, $"Question with index={index} in test with id={testId} does not exist.")); } return(this.Ok(_questionService.GetQuestionByIndexAndTestId(index, testId))); }
/// <summary> /// Add an answer for the given question to the current session /// </summary> /// <returns>Answer result.</returns> /// <param name="pQuestion">Question.</param> /// <param name="pAnswers">Answers.</param> public ResponseDTO <AnswerResultDTO> AddAnswer(QuestionDTO pQuestion, IEnumerable <AnswerDTO> pAnswers) { SessionAnswerDTO sessionAnswer = new SessionAnswerDTO { Session = CurrentSession, Question = pQuestion, Answers = pAnswers.ToList(), AnswerTime = (DateTime.Now - pQuestion.ShowedMoment).Seconds }; return(_operativeService.AddAnswer(sessionAnswer)); }
public bool Update(QuestionDTO question) { bool isUpdated = _database.Questions.Update(question.Id, Mapper.Map <QuestionDTO, Question>(question)); if (isUpdated) { _database.Save(); return(true); } return(false); }
private static Question CreateFromDTO(QuestionDTO questionDTO) { var question = new Question { QuestionText = questionDTO.QuestionText, QuestionExplanation = questionDTO.QuestionExplanation, TopicId = questionDTO.TopicId }; return(question); }
public async Task <QuestionDTO> AddQuestionAsync(QuestionDTO question) { var questionDTO = Mapper.Map <QuestionDTO, Question>(question); await UnitOfWork.Question.CreateAsync(questionDTO); var allQuestions = await UnitOfWork.Question.GetAllAsync(); var newQuestion = allQuestions.Where(x => x.Name == question.Name).FirstOrDefault(); var newQuestionMapped = Mapper.Map <Question, QuestionDTO>(newQuestion); return(newQuestionMapped); }
public ActionResult UpdateQuestion(QuestionDTO ques) { try { string message = QuestionDAO.UpdateQuestion(ques); return(Ok(message)); } catch (Exception) { return(BadRequest()); } }
public int CreateQuestion(QuestionDTO question, int topicID) { Question newQuestion = Mapping.Mapper.Map <Question>(question); Topic topic = context.Topics.Find(topicID); newQuestion.Topic = topic; context.Database.Log = Console.WriteLine; context.Questions.Add(newQuestion); context.SaveChanges(); return(newQuestion.QuestionID); }
public ActionResult EditQuestion(Guid id, Guid subjectId, Guid idExam) { QuestionDTO questionDTO = questionService.GetQuestionById(id); if (questionDTO != null) { ViewBag.idExam = idExam; ViewBag.subjectId = subjectId; return(View(questionDTO)); } return(HttpNotFound()); }
public bool UpdateQuestion(QuestionDTO question) { Question ques = questionRepository.Get(question.Id); if (ques == null) { return(false); } ques.Content1 = question.Content1; ques.Content2 = question.Content2; return(questionRepository.Update(ques)); }
public void Update(QuestionDTO entity) { Question result = DataConverter.QuestionDTOToEntity(entity); using (var context = new DemoContext()) { var found = context.Questions.Find(result.QuestionId); found.Text = entity.Text; found.ModifiedDate = DateTime.Now; context.SaveChanges(); } }
public async Task <IActionResult> AddQuestion([FromBody] QuestionDTO questionDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _service.AddQuestionAsync(questionDTO); // return Ok(result); //return CreatedAtAction("GetQuestion", new { id = questionsDTO.Id }, questionsDTO); return(Ok(result)); }
public static void TransactionTest(QuestionDTO entity) { string connectionString = ConnectionStringHelper.GetConnStringFromConfigFile(); int questionTypeId = 100; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); // Start a local transaction. SqlTransaction sqlTran = connection.BeginTransaction(); // Enlist a command in the current transaction. SqlCommand command = new SqlCommand();// connection.CreateCommand(); command.Transaction = sqlTran; command.Connection = connection; try { command.CommandText = "INSERT INTO [dbo].[Question] ([Text], [QuestionTypeID]) VALUES.(@text, @questionTypeId"; command.Parameters.Add("@text", SqlDbType.VarChar, 200).Value = entity.Text; command.Parameters.Add("@questionTypeId", SqlDbType.Int).Value = questionTypeId; command.ExecuteNonQuery(); // Commit the transaction. sqlTran.Commit(); Console.WriteLine("Both records were written to database."); } catch (Exception ex) { // Handle the exception if the transaction fails to commit. Console.WriteLine(ex.Message); try { // Attempt to roll back the transaction. sqlTran.Rollback(); } catch (Exception exRollback) { Console.WriteLine(exRollback.Message); } } finally { connection.Close(); } } }
public IHttpActionResult CreateQuestion([FromBody] QuestionBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } QuestionDTO newQuestion = _mapper.Map <QuestionDTO>(model); this._questionService.Add(newQuestion); return(Ok()); }
public ActionResult Edit([Bind(Include = "Test_ID,Question_ID,content")] QuestionViewModel question) { if (ModelState.IsValid) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <QuestionViewModel, QuestionDTO>()).CreateMapper(); QuestionDTO questionDTO = mapper.Map <QuestionViewModel, QuestionDTO>(question); //questionDTO.Test_ID = id.Value; QuestionService.EditQuestion(questionDTO); return(RedirectToAction("Details", "Tests", new { id = questionDTO.Test_ID })); } //ViewBag.Test_ID = new SelectList(testService.GetTests(), "Test_ID", "Topic", question.Test_ID); return(View(question)); }
public static QuestionDTO Map(CreateQuestionViewModel viewmodel) { QuestionDTO dto = new QuestionDTO { Question = viewmodel.Question }; foreach (var answer in viewmodel.Answers) { dto.Answers.Add(DTOMapper.Map(answer)); } return(dto); }
public static Question QuestionDTOToEntity(QuestionDTO DTOObject) { return(new Question { QuestionId = DTOObject.QuestionId, Text = DTOObject.Text, QuestionTypeId = DTOObject.QuestionTypeId, IsActive = DTOObject.IsActive, IsRequired = DTOObject.IsRequired, CreateDate = DTOObject.CreateDate, ModifiedDate = DTOObject.ModifiedDate }); }
public void Add(QuestionDTO entity) { SqlParameter[] parameter = new SqlParameter[2]; string connectionString = ConnectionStringHelper.GetConnStringFromConfigFile(); string commandText = "INSERT INTO [dbo].[Questions]([Description],[QuestionTypeId])VALUES(@Description,@QuestionTypeId)"; parameter[0] = new SqlParameter("@Description", entity.Text); parameter[1] = new SqlParameter("@QuestionTypeId", entity.QuestionTypeId); int rows = CommandHelper.ExecuteNonQuery(connectionString, commandText, CommandType.Text, parameter); Console.WriteLine("{0} row(s) inserted", rows); }
public async Task <IActionResult> CreateQuestion([FromBody] QuestionDTO questionDto) { try { var question = await _questionService.CreateQuestionAsync(questionDto); return(Ok(_mapper.Map <QuestionDTO>(question))); } catch (TrojkatyCoreException ex) { return(BadRequest(new { message = ex.Message })); } }
public ActionResult Create([Bind(Include = "Question_ID,content,ISFULL,Test_ID, Topic")] QuestionViewModel question, int?id) { if (ModelState.IsValid) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <QuestionViewModel, QuestionDTO>()).CreateMapper(); QuestionDTO questionDTO = mapper.Map <QuestionViewModel, QuestionDTO>(question); questionDTO.Test_ID = id.Value; // questionDTO.ISFULL = question.ISFULL; QuestionService.CreateQuestion(questionDTO); return(RedirectToAction("Details", "Tests", new { id = questionDTO.Test_ID })); } return(View(question)); }
public void DeleteQuestion(QuestionDTO question) { var newQuestion = Mapping.Mapper.Map <Question>(question); using (var context = new AppDbContext()) { //context.Database.Log = Console.WriteLine; context.ThematicAreas.Find(newQuestion.ThematicArea).Questions.Remove(newQuestion); context.Entry(newQuestion).State = EntityState.Deleted; context.SaveChanges(); } }
public string CreateQuestion(QuestionDTO question) { Question newQuestion = new Question { Id = Guid.NewGuid(), Content1 = question.Content1, Content2 = question.Content2, ChapterId = question.Id, Index = questionRepository.CurrentIndex(question.Id) + 1 }; return(questionRepository.Create(newQuestion) ? newQuestion.Id.ToString() : ""); }
public void UpdateQuestion(QuestionDTO question) { var tempFile = Path.GetTempFileName(); var allLines = File.ReadAllLines(dataFile); allLines[question.Id] = ToDataFileLine(question); File.WriteAllLines(tempFile, allLines); File.Delete(dataFile); File.Move(tempFile, dataFile); }