public void Add_Success() { var sample = _repo.Add(Lorem.Sentence(), "Happy"); var result = _repo.Get(sample.Id); Assert.IsNotNull(result); }
public int InsertOrUpdateQuestionOfQuiz(Question question) { if (question != null && question.Id == 0) { for (int i = 0; i < question.Answers.Count; i++) { question.Answers.ElementAt(i).Id = 0; // question.Answers.ElementAt(i).QuestionId = question.Id; } questionRepository.Add(question); // answerRepository.AddMany(question.Answers.ToList()); return(1); } else if (question != null && question.Id != 0) { questionRepository.Update(question); return(1); } else { return(0); } }
public async Task <ActionResult> CreateQuestion([FromBody] QuestionDTO model) { if (ModelState.IsValid) { var ce = await GetOrCreateCategoryExhibitor(model.CategoryId, model.ExhibitorId); var question = new Question() { QuestionText = model.QuestionText, Answer = model.AnswerText, CategoryExhibitor = ce }; question = _questionRepository.Add(question); //_categoryExhibitorRepository.Add(question.CategoryExhibitor); await _questionRepository.SaveChanges(); return(Ok(question)); } return(Ok( new { Message = "Zorg dat naam ingevuld is." })); }
public async Task <ActionResult> CreateQuestion([FromBody] CreateQuestionDto question) { if (question == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } if (await _repository.isQuestionTextExist(question.QuestionText)) { return(BadRequest("The question text inputed already exist")); } var questionToAdd = _mapper.Map <Question>(question); _repository.Add(questionToAdd); if (!await _repository.SaveChangesAsync()) { throw new Exception("An error occured while trying to save question"); } return(CreatedAtRoute("GetQuestion", new { questionId = questionToAdd.Id }, _mapper.Map <QuestionDto>(questionToAdd))); }
public async Task<IActionResult> Create( [FromBody] QuestionDef Question ) { if( Question == null ) { return BadRequest(); } await _questionRepo.Add( Question ); return CreatedAtRoute( "GetQuestion", new { Controller = "Questions", id = Question.QuestionId }, Question ); }
public async Task <ValidationResult> Handle(RegisterNewQuestionCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { return(message.ValidationResult); } var question = new Question(0, message.QuestionDescription, message.ImageUrl, message.ThumbUrl, DateTime.Now); if (await _questionRepository.GetByDescription(message.QuestionDescription) != null) { AddError("The question description has already exists."); return(ValidationResult); } _questionRepository.Add(question); var result = await Commit(_questionRepository.UnitOfWork); if (result.IsValid) { foreach (var choice in message.Choices) { _questionChoiceRepository.Add(new QuestionChoice(0, question.Id, choice, 0)); } question.AddDomainEvent(new QuestionRegisteredEvent(question.Id, question.QuestionDescription, question.ImageUrl, question.ThumbUrl, question.PublishedAt)); return(await Commit(_questionChoiceRepository.UnitOfWork)); } return(result); }
public QuestionModel AskQuestion(SubjectModel subject) { if (!new SubjectValidator(subject).Validate(out string errorCode)) { throw new DefinedException(GetLocalizedResource(errorCode)); } Question result = null; _questionRepository.UseTransaction(() => { var user = _userRepository.Get(UserId); if (user == null) { throw new DefinedException(GetLocalizedResource(ErrorDefinitions.User.UserNotFound)); } result = _questionRepository.Add(new Question(subject.Title, subject.Content, subject.CategoryId, UserId)); _questionRepository.SaveChanges(); user.UserScores.IncreaseContribution((int)ContributeTypeDefinition.NewQuestionAdded, new NewQuestionContributionRule().IncreasingValue, result.Id); _questionRepository.SaveChanges(); }); return(QuestionModel(result)); }
public QuestionResponseModel CreateQuestion(QuestionRequestModel requestModel) { var newQuestion = new Question { QuestionDescription = requestModel.Question, ImageUrl = requestModel.ImageUrl, ThumbUrl = requestModel.ThumbUrl, PublishedAt = DateTime.Now }; foreach (var choice in requestModel.Choices.Distinct()) // Distinct - If there are choices with same name { newQuestion.QuestionChoices.Add(new QuestionChoice { Name = choice, Votes = 0 }); } var dbQuestion = questionRepo.Add(newQuestion); questionRepo.Save(); return(MapToQuestionModel(dbQuestion)); }
public UpdateResult Create(Model.Models.Survey survey) { UpdateResult result = new UpdateResult(); try { _surveyRepository.Add(survey); Save(); foreach (Question question in survey.Questions) { question.SurveyId = survey.Id; _questionRepository.Add(question); } Save(); foreach (Question question in survey.Questions) { foreach (Answer answer in question.Answers) { answer.QuestionId = question.Id; _answerRepository.Add(answer); } } Save(); } catch (Exception exception) { result.State = 4; result.KeyLanguage = UpdateResult.ERROR_WHEN_UPDATED; } return(result); }
public void Add(QuestionDto questionDto, string userId, string questionUserId) { questionDto.AnswerUserId = userId; questionDto.QuestionUserId = questionUserId; Question question = _mapper.Map <Question>(questionDto); _questionRepository.Add(question, userId, questionUserId); }
public Question Add(Question newQuestion) { if (newQuestion.Answers.Count(a => a.IsCorrect) != 1) { throw new ApplicationException("A question should have exactly one correct answer."); } return(_questionRepo.Add(newQuestion)); }
public Question Add(Question newQuestion) { CheckAnswers(newQuestion.Answers); newQuestion = _questionRepository.Add(newQuestion); return(newQuestion); }
public QuestionDto Add(QuestionDto questionDto) { var question = _mapper.Map <Question>(questionDto); _questionRepository.Add(question); var createdQuestion = _mapper.Map <QuestionDto>(question); return(createdQuestion); }
public ActionResult AddQuestion(QuestionInput question) { if (!ModelState.IsValid) { return(View(question)); } repository.Add(question.ToQuestion()); return(RedirectToAction("Index")); }
public IActionResult addQuestion([FromBody] Question model) { try { return(new ObjectResult(_question.Add(model))); } catch { return(BadRequest()); } }
public QuestionDto Add(QuestionDto questionDto) { var question = _mapper.Map <Question>(questionDto); question.CreationTime = DateTime.Now; _questionRepository.Add(question); var createdQuestion = _mapper.Map <QuestionDto>(question); return(createdQuestion); }
public void Ask(Guid listingId, Guid memberId, string question) { var listing = _listings.FindBy(listingId); using (DomainEvents.Register(QuestionSubmitted())) { var aQuestion = listing.AskQuestion(memberId, question, _clock.Time()); _questions.Add(aQuestion); } }
public async Task <QuestionViewModel> AskQuestion(QuestionViewModel model, long userId) { var entity = _mapper.Map <Question>(model); entity.UserId = userId; entity = _questionRepository.Add(entity); await _uow.CommitAsync(); var result = _mapper.Map <QuestionViewModel>(entity); return(result); }
private void CustomiseAndAddSampleQuestions(IEnumerable <Question> questions) { var identifier = 1; foreach (var question in questions) { var localQuestion = question; localQuestion.Id = identifier.ToString(CultureInfo.InvariantCulture); localQuestion.UserIdAsked = identifier + 10; localQuestion.UserIdAnswered = identifier < 3 ? 100 : 200; localQuestion.Text = GetSampleQuestionText(identifier); localQuestion.Answers = new QuestionAnswer[] { }; switch (identifier) { case 1: SetSampleQuestionAsNew(localQuestion); break; case 2: SetSampleQuestionAsApproved(localQuestion); break; case 3: SetSampleQuestionAsNew(localQuestion); localQuestion.Answers = new[] { GetSampleQuestionAnswer(identifier) }; break; case 4: SetSampleQuestionAsRemoved(localQuestion); localQuestion.Answers = new[] { GetSampleQuestionAnswer(identifier) }; break; case 5: SetSampleQuestionAsReplied(localQuestion); break; case 6: SetSampleQuestionAsArchived(localQuestion); break; case 7: SetSampleQuestionAsReplied(localQuestion); break; } identifier++; AsyncHelpers.RunSync(() => repository.Add(localQuestion)); } }
public async void Add_RemoveById_CanAddNewQuestionThenRemoveByIdentifier() { var fixture = new Fixture(); var question = fixture.Build <Question>().Create(); const string newQuestionId = "99"; question.Id = newQuestionId; await repository.Add(question); var questionFromRepo = await repository.GetById(newQuestionId); if (questionFromRepo == null) { return; } questionFromRepo.ShouldNotBeNull(); questionFromRepo.Id.ShouldEqual(newQuestionId); AsyncHelpers.RunSync(() => repository.RemoveById(newQuestionId)); }
public async Task <IActionResult> Create([Bind("QuestionId,QuizId,QuestionText")] Question question) { if (ModelState.IsValid) { _questionRepository.Add(question); await _questionRepository.Save(); TempData["info"] = "The question text has been saved."; return(RedirectToAction(nameof(Create), "Answers", new { id = question.QuestionId })); } return(View(question)); }
public IActionResult Add_Question() { int id = int.Parse(Request.Form["id"]); string title = Request.Form["Title"]; string number = Request.Form["Answers"]; Question quest = new Question() { Title = title, QuestionTime = int.Parse(number), QuestionId = id }; q.Add(quest); q.Save(); return(View()); }
public async Task <Result <QuestionResponse> > Add(AddQuestionCommand command) { var validationResult = Validate(await _addQuestionCommandValidator.Validate(command)); if (!validationResult.Success) { return(validationResult); } var question = command.ToQuestion(); await _repository.Add(question); return(new Result <QuestionResponse>(new QuestionResponse())); }
public void AddQuestion(QuestionDto question, string operatedBy) { var entity = QuestionFactory.CreateInstance(question.Subject, question.Remark, operatedBy); _questionRepository.Add(entity); var tags = question.Tags; foreach (var item in tags) { var tag = QuestionTagFactory.CreateInstance(item.Name, entity.Id); _questionTagRepository.Add(tag); } _dbUnitOfWork.Commit(); }
public async Task <IActionResult> CreateQuestion(int valueId, QuestionForCreationDto question) { question.ValueId = valueId; var questionFromMapper = mapper.Map <Question>(question); repository.Add(questionFromMapper); if (await repository.SaveAll()) { var questionToReturn = mapper.Map <QuestionForReturnDto>(questionFromMapper); return(Ok(questionToReturn)); } return(BadRequest("Nie udało sie dodać zapytania")); }
public async Task <IActionResult> Add(Questions que) { Console.WriteLine("in the adding if\n"); Console.WriteLine(que.Subject); _QuestionRepository.Add(que); if (await _QuestionRepository.SaveChangesAsync()) { ViewBag.msg = "Question Added Successfully"; return(View()); } else { return(View(que)); } }
public MessageReport Create(Question question) { var rp = new MessageReport(); try { _IQuestionRepository.Add(question); rp.Success = true; rp.Message = "Thêm câu hỏi thành công!"; } catch (Exception ex) { rp.Message = ex.Message; } return(rp); }
[Consumes("application/json")] // application/xml public IActionResult Post([FromBody] QuestionDto model) // Deserialize, 생성 전용 DTO 클래스 사용 가능 { // 예외 처리 방법 if (model == null) { return(BadRequest()); // Status: 400 Bad Request } try { // 예외 처리 if (model.Title == null || model.Title.Length < 1) { ModelState.AddModelError("Title", "문제를 입력해야 합니다."); } // 모델 유효성 검사 if (!ModelState.IsValid) { return(BadRequest(ModelState)); // 400 에러 출력 } // QuestionDto를 Question 모델로 변경해서 리포지토리에 전달 // AutoMapper Mapper.Map() 형식으로 대체 가능 var newModel = new Question { Id = model.Id, Title = model.Title }; var m = _repository.Add(newModel); // 저장 if (DateTime.Now.Second % 2 == 0) //[!] 둘 중 원하는 방식 사용 { //return CreatedAtAction("GetById", new { id = m.Id }, m); return(CreatedAtRoute("GetQuestionById", new { id = m.Id }, m)); // Status: 201 Created } else { var uri = Url.Link("GetQuestionById", new { id = m.Id }); return(Created(uri, m)); // 201 Created } //return Ok(m); // 200 } catch (Exception) { return(BadRequest()); } } // </Post>
public async Task <CreateQuestionResponse> CreateOrUpdateQuestionAsync(Question question) { // TODO :: CHECK IF SUBTEST's TEST BELONGS TO TOKEN USER //https://stackoverflow.com/questions/46112258/how-do-i-get-current-user-in-net-core-web-api-from-jwt-token if (question.Id == 0) { _questionRepository.Add(question); } else { _questionRepository.Update(question); } await _unitOfWork.CompleteAsync(); return(new CreateQuestionResponse(true, null, question)); }
public Question Add(Question question) { if (question.Answers.Count < 2) { throw new Exception(" need more answer choices"); } else { var count = question.Answers.Count(a => a.IsCorrect == true); if (count != 1) { throw new Exception("more than one correct answer"); } } return(_questionRepository.Add(question)); }