public bool CheckBoxValidation(List <MultipleChoiceAnswer> multipleChoiceAnswers) { foreach (MultipleAnswersQuestion checkBoxQuestion in MultipleAnswersQuestions) { Debug.WriteLine("[Submit] Question: " + checkBoxQuestion.Question); List <string> selectedOptions = new List <string>(); bool validateCheckbox = false; Debug.WriteLine("[Validate submit] " + validateCheckbox); foreach (Option option in checkBoxQuestion) { if (option.IsSelected) { validateCheckbox = true; selectedOptions.Add(option.OptionText); Debug.WriteLine("[Submit] Answer: " + option.OptionText); } } if (validateCheckbox == false) { return(false); } MultipleChoiceAnswer answer = new MultipleChoiceAnswer { Question = checkBoxQuestion.Question, Answers = selectedOptions }; multipleChoiceAnswers.Add(answer); } return(true); }
public async Task <ActionResult> SaveMultipleChoiceAnswer(MultipleChoiceAnswer multipleChoiceAnswer) { var questionId = int.Parse(Request.Form["QuestionId"].ToString()); if (multipleChoiceAnswer.Id != 0) { var answer = await _questionnaireService.GetAnswer <MultipleChoiceAnswer>(multipleChoiceAnswer.Id); if (answer != null) { answer.MultipleChoiceAnswerKey = multipleChoiceAnswer.MultipleChoiceAnswerKey; } await _questionnaireService.SaveChangesAsync(); } else { multipleChoiceAnswer.Question = await _questionnaireService.GetQuestion(questionId); multipleChoiceAnswer.PlannedInspection = await _questionnaireService.GetPlannedInspection(multipleChoiceAnswer.PlannedInspection.Id); await _questionnaireService.CreateAnswer(multipleChoiceAnswer); } return(RedirectToAction("Details", new { id = multipleChoiceAnswer.PlannedInspection.Id })); }
public bool RadioButtonValidation(List <MultipleChoiceAnswer> multipleChoiceAnswers) { ActivityIndicator = true; foreach (SingleAnswerQuestion radioButtonQuestion in SingleAnswerQuestions) { if (radioButtonQuestion.SelectedOption == -1) { Debug.WriteLine("nenhuma questão selecionada"); ActivityIndicator = false; return(false); } int answerIndex = radioButtonQuestion.SelectedOption; MultipleChoiceAnswer answer = new MultipleChoiceAnswer { Question = radioButtonQuestion.Question, Answers = new List <string> { radioButtonQuestion.Options[answerIndex] } }; multipleChoiceAnswers.Add(answer); Debug.WriteLine("[Submit] Question: " + radioButtonQuestion.Question); Debug.WriteLine("[Submit] Answer: " + radioButtonQuestion.Options[answerIndex]); } ActivityIndicator = false; return(true); }
void OnClick() { MultipleChoiceAnswer alternative = new MultipleChoiceAnswer(); alternative.questionId = 1.ToString(); alternative.alternativeId = 2.ToString(); LOLSDK.Instance.SubmitAnswer(alternative); }
public void CreateQuestionVsMultipleChoiceAnswer(Question question, MultipleChoiceAnswer answer) { QuestionsVsMultipleChoiceAnswer questionVsAnswer = new QuestionsVsMultipleChoiceAnswer(); DB.Questions.Where(q => q.questionBody == question.questionBody).Single().QuestionsVsMultipleChoiceAnswers.Add(questionVsAnswer); DB.MultipleChoiceAnswers.Where(m => m.choiceBody == answer.choiceBody).Single().QuestionsVsMultipleChoiceAnswers.Add(questionVsAnswer); DB.SaveChanges(); }
public void AddAnswer(MultipleChoiceAnswer _answer) { if (_answer != null) { context.MultipleChoiseAnswers.Add(_answer); context.SaveChanges(); } }
public async Task <ActionResult> DeleteConfirmed(Guid id) { MultipleChoiceAnswer multipleChoiceAnswer = await db.MultipleChoiceAnswers.FindAsync(id); db.MultipleChoiceAnswers.Remove(multipleChoiceAnswer); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public void CheckingAnswer_FullyGoodAnswer() { var Answer = new MultipleChoiceAnswer() { SelectedAnswerIndex = 0, }; var points = Question.CheckAnswer(Answer); Assert.AreEqual(FullPointScore, points); }
public void CheckingAnswer_WrongAnswer_WrongAnswerIndex() { var Answer = new MultipleChoiceAnswer() { SelectedAnswerIndex = 9991, }; var points = Question.CheckAnswer(Answer); Assert.AreEqual(0, points); }
public IActionResult Reply(FormReplyDTO formReply) { FormReply reply = new FormReply() { Answers = new List <Answer>(), Email = formReply.Email }; foreach (FormAnswerDTO formAnswer in formReply.Answers) { Answer answer; switch (formAnswer.FieldType) { case FieldType.OpenText: answer = new OpenTextAnswer() { Value = formAnswer.Reply }; break; case FieldType.MultipleChoice: answer = new MultipleChoiceAnswer() { SelectedChoices = formAnswer.MultipleAnswer.ToList() }; break; case FieldType.DropDown: case FieldType.SingleChoice: answer = new SingleChoiceAnswer() { SelectedChoice = formAnswer.SelectedChoice }; break; case FieldType.Statement: answer = new SingleChoiceAnswer() { SelectedChoice = formAnswer.SelectedChoice }; break; default: throw new NotSupportedException("Fieldtype not supported yet"); } reply.Answers.Add(answer); } _formManager.AddFormReply(reply); _unitOfWorkManager.Save(); return(Ok()); }
public QuestionAnswered(int aQuestionIndex, string questionId, int aAlternativeIndex, string alternativeId, int aCorrectAlternativeIndex) { questionIndex = aQuestionIndex; alternativeIndex = aAlternativeIndex; correctAlternativeIndex = aCorrectAlternativeIndex; answer = new MultipleChoiceAnswer(); answer.questionId = questionId; answer.alternativeId = alternativeId; mIsSubmitted = false; }
public async Task <ActionResult> Edit([Bind(Include = "MultipleChoiceAnswersId,QuestionId,Answer,AnswerNo,QuestionnaireId")] MultipleChoiceAnswer multipleChoiceAnswer) { if (ModelState.IsValid) { db.Entry(multipleChoiceAnswer).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.QuestionId = new SelectList(db.questions, "QuestionId", "Question1", multipleChoiceAnswer.QuestionId); ViewBag.QuestionnaireId = new SelectList(db.Questionnaires, "QuestionnaireId", "QuestionnaireId", multipleChoiceAnswer.QuestionnaireId); return(View(multipleChoiceAnswer)); }
private void ReadoutAnswers(IEnumerable <Answer> answers) { foreach (Answer answer in answers) { _pdfHtml += answer switch { FileAnswer fileAnswer => $"<p>{GetEmployee(fileAnswer).Name}: {fileAnswer.UploadedFilePath}", StringAnswer stringAnswer => $"<p>{GetEmployee(stringAnswer).Name}: {stringAnswer.AnswerContents}</p>", NumericAnswer numericAnswer => $"<p>{GetEmployee(numericAnswer).Name}: {numericAnswer.IntAnswer}</p>", MultipleChoiceAnswer multiplechoiceAnswer => $"<p>{GetEmployee(multiplechoiceAnswer).Name}: {((MultipleChoiceQuestion)multiplechoiceAnswer.Question).OptionCollection[multiplechoiceAnswer.MultipleChoiceAnswerKey].Value}</p>", _ => "" }; } }
// GET: MultipleChoiceAnswers/Details/5 public async Task <ActionResult> Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MultipleChoiceAnswer multipleChoiceAnswer = await db.MultipleChoiceAnswers.FindAsync(id); if (multipleChoiceAnswer == null) { return(HttpNotFound()); } return(View(multipleChoiceAnswer)); }
public override QuestionAnswer Deserialize(string serializeData) { if (string.IsNullOrWhiteSpace(serializeData)) { return(null); } var options = JsonUtility.JsonDeserialize <List <AnswerChoiceOption> >(serializeData); var answer = new MultipleChoiceAnswer(); answer.PushRange(options); return(answer); }
public async Task <ActionResult> Create([Bind(Include = "MultipleChoiceAnswersId,QuestionId,Answer,AnswerNo,QuestionnaireId")] MultipleChoiceAnswer multipleChoiceAnswer) { if (ModelState.IsValid) { multipleChoiceAnswer.MultipleChoiceAnswersId = Guid.NewGuid(); db.MultipleChoiceAnswers.Add(multipleChoiceAnswer); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.QuestionId = new SelectList(db.questions, "QuestionId", "Question1", multipleChoiceAnswer.QuestionId); ViewBag.QuestionnaireId = new SelectList(db.Questionnaires, "QuestionnaireId", "QuestionnaireId", multipleChoiceAnswer.QuestionnaireId); return(View(multipleChoiceAnswer)); }
public void Validate_InvalidAnswer_ReturnFalse() { // arrange var container = CreateContainer(); var wrapper = new PollAnswerValidatorWrapper(container); var instruction = new MultipleChoiceInstruction(new[] { "A", "B" }, null); var answer = new MultipleChoiceAnswer(new[] { "C" }); // act var result = wrapper.Validate(instruction, answer); // assert Assert.NotNull(result); }
public ActionResult GetQuizResult(MultipleChoiceAnswer _answer) { if (string.IsNullOrEmpty(_answer.Answer)) { ModelState.AddModelError("", "You need to choose answer"); ViewBag.Radiobutton = GetRandomRadiobutton(); return(PartialView("StatisticPartialView", new StatisticViewModel())); } var sm = new StatisticManager(); repository.AddAnswer(_answer); StatisticViewModel statisticView = sm.GetQuestionStatistic(repository.GetMultipleQuestion(_answer.QuestionId)); return(PartialView("StatisticPartialView", statisticView)); }
// GET: MultipleChoiceAnswers/Edit/5 public async Task <ActionResult> Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MultipleChoiceAnswer multipleChoiceAnswer = await db.MultipleChoiceAnswers.FindAsync(id); if (multipleChoiceAnswer == null) { return(HttpNotFound()); } ViewBag.QuestionId = new SelectList(db.questions, "QuestionId", "Question1", multipleChoiceAnswer.QuestionId); ViewBag.QuestionnaireId = new SelectList(db.Questionnaires, "QuestionnaireId", "QuestionnaireId", multipleChoiceAnswer.QuestionnaireId); return(View(multipleChoiceAnswer)); }
private async Task SaveMultipleChoiceAnswers(ICollection <MultipleChoiceQuestionDTO> multipleQuestions, Guid token) { foreach (var question in multipleQuestions) { foreach (var option in question.Options) { if (option.Answer != null) { var answer = new MultipleChoiceAnswer(); answer.MultipleChoiceQuestionId = question.Id; answer.Answer = option.Answer; answer.CorelationToken = token; await this.dbcontext.MultipleChoiceAnswers.AddAsync(answer); } } } }
public void AlternativeClicked(int ctr) { Alternative alternative = this.currentQuestion.alternatives[ctr]; MultipleChoiceAnswer answer = new MultipleChoiceAnswer(); answer.alternativeId = alternative.alternativeId; answer.questionId = this.currentQuestion.questionId; LOLSDK.Instance.SubmitAnswer(answer); int correctId = -1; _altButtonColor = alternativeButtons[ctr].colors.normalColor; for (int i = 0; i < alternativeButtons.Length; ++i) { alternativeButtons[i].interactable = false; if (this.currentQuestion.correctAlternativeId.Equals(this.currentQuestion.alternatives[i].alternativeId)) { correctId = i; } } if (this.currentQuestion.correctAlternativeId.Equals(answer.alternativeId)) { //SetFieldText("MessageText", "Good Job!!"); SetBlinkRight(alternativeButtons[ctr]); PlaySfx(answer_correct_sfx_str); ++rightAnswers; } else { //SetFieldText("MessageText", "Sorry, but wrong!"); SetBlinkRight(alternativeButtons[correctId]); SetBlinkWrong(alternativeButtons[ctr]); PlaySfx(answer_wrong_sfx_str); } StartCoroutine(GoToNextQuestion()); }
private static void AddMultipleChoiceQuestion( ApplicationDbContext dbContext, string quote, string correctAuthor) { var quoteId = dbContext.Quotes.FirstOrDefault(q => q.Content == quote)?.Id; var authorId = dbContext.Authors.FirstOrDefault(a => a.Name == correctAuthor)?.Id; var firstIncrAuthor = dbContext.Authors.FirstOrDefault(a => a.Id != authorId); var secIncrAuthor = dbContext.Authors.FirstOrDefault(a => a.Id != authorId && a.Id != firstIncrAuthor.Id); var multipleChoiceQuestion = new MultipleChoiceQuestion { QuoteId = quoteId.Value, CorrectAuthorId = authorId.Value }; dbContext.MultipleChoiceQuestions.Add(multipleChoiceQuestion); dbContext.SaveChanges(true); var answerX = new MultipleChoiceAnswer { MultipleChoiceQuestionId = multipleChoiceQuestion.Id, AuthorChoiceId = firstIncrAuthor.Id }; var answerY = new MultipleChoiceAnswer { MultipleChoiceQuestionId = multipleChoiceQuestion.Id, AuthorChoiceId = secIncrAuthor.Id }; dbContext.MultipleChoiceAnswers.AddRange(new List <MultipleChoiceAnswer> { answerY, answerX }); dbContext.SaveChanges(); }
/// <summary> /// Submits the current question /// </summary> private void Submit() { // Check which answer is selected var CurrentlySelectedIdx = CheckWhichAnswerIsSelected(); // If none, show error and don't submit if (CurrentlySelectedIdx == 0) { NoAnswerWarning = true; return; } // Save the answer var answer = new MultipleChoiceAnswer() { SelectedAnswerIndex = CurrentlySelectedIdx - 1, }; mTestHost.SaveAnswer(answer); // Go to next question page mTestHost.GoNextQuestion(); }
public IActionResult PostIdeationReply([FromForm] IdeationReplyDTO ideationReplyDto) { // return Created("/ideation/overview/1", null); //log test 1 Ideation ideation = _ideationManager.GetIdeationWithQuestions(ideationReplyDto.IdeationId); //log test 2 User user = _usermanager.GetUserAsync(User).Result; //log test 3 if (ideation == null || user == null) { return(NotFound()); } //log test 4 IdeationReply newReply = new IdeationReply() { Ideation = ideation, Title = ideationReplyDto.Title, Answers = new List <Answer>(), Votes = new List <Vote>(), Comments = new List <Comment>(), Created = DateTime.Now, User = user, Reports = new List <IdeationReport>() }; //log test 5 int index = 0; ideationReplyDto.Answers.ForEach(dto => { Answer newAnswer = null; switch (dto.FieldType) { case FieldType.OpenText: newAnswer = new OpenTextAnswer() { QuestionIndex = dto.QuestionIndex, Value = dto.OpenAnswer }; break; case FieldType.Image: case FieldType.Video: string fileName = Util.Util.GenerateDataStoreObjectName(dto.FileAnswer.FileName); string pathName = _fileUploader.UploadFile(fileName, "ideationReply", dto.FileAnswer).Result; newAnswer = new MediaAnswer() { QuestionIndex = dto.QuestionIndex, Value = new Media() { Name = dto.FileAnswer.FileName, Url = pathName } }; break; case FieldType.SingleChoice: case FieldType.DropDown: newAnswer = new SingleChoiceAnswer() { QuestionIndex = dto.QuestionIndex, SelectedChoice = dto.SingleAnswer }; break; case FieldType.MultipleChoice: newAnswer = new MultipleChoiceAnswer() { QuestionIndex = dto.QuestionIndex, SelectedChoices = dto.MultipleAnswer }; break; case FieldType.Location: newAnswer = new LocationAnswer() { QuestionIndex = dto.QuestionIndex, Value = new Location() { Latitude = dto.LocationAnswer.Latitude, Longitude = dto.LocationAnswer.Longitude, ZoomLevel = dto.LocationAnswer.ZoomLevel, } }; break; default: throw new ArgumentOutOfRangeException(); } newAnswer.OrderIndex = index++; newReply.Answers.Add(newAnswer); }); //log test 6 _ideationManager.AddIdeationReply(newReply); //log test 7 // Create activity var activity = CreateActivity(ActivityType.IdeationReply, user); activity.IdeationReply = newReply; _activityManager.AddActivity(activity); //log test 8 // Save everything _unitOfWorkManager.Save(); //log test 9 // Push activity var activityVm = new ActivityViewModel(activity); //log test 10 PushWebsockets(activityVm).Wait(); //log test 11 return(Created("/ideation/view/" + newReply.IdeationReplyId, new { id = newReply.IdeationReplyId })); }
public IActionResult PostIdeationReplyApp([FromBody] IdeationReplyAppDto ideationReplyApp) { Ideation ideation = _ideationManager.GetIdeationWithReplies(ideationReplyApp.IdeationId); User user = _usermanager.FindByEmailAsync(HttpContext.User.Claims.FirstOrDefault(c => c.Type == "Email").Value).Result; IdeationReply newReply = new IdeationReply() { Ideation = ideation, Title = ideationReplyApp.Title, Answers = new List <Answer>(), Votes = new List <Vote>(), Created = DateTime.Now, Comments = new List <Comment>(), User = user, Reports = new List <IdeationReport>() }; int index = 0; foreach (var dto in ideationReplyApp.Answers) { Answer newAnswer = null; switch (dto.FieldType) { case FieldType.OpenText: newAnswer = new OpenTextAnswer() { QuestionIndex = dto.QuestionIndex, Value = dto.Reply }; break; case FieldType.SingleChoice: case FieldType.DropDown: newAnswer = new SingleChoiceAnswer() { QuestionIndex = dto.QuestionIndex, SelectedChoice = dto.SelectedChoice }; break; case FieldType.MultipleChoice: newAnswer = new MultipleChoiceAnswer() { QuestionIndex = dto.QuestionIndex, SelectedChoices = dto.MultipleAnswer }; break; case FieldType.Location: newAnswer = new LocationAnswer() { QuestionIndex = dto.QuestionIndex, Value = new Location() { Latitude = dto.LocationAnswer.Latitude, Longitude = dto.LocationAnswer.Longitude, ZoomLevel = dto.LocationAnswer.ZoomLevel, } }; break; default: throw new ArgumentOutOfRangeException(); } newAnswer.OrderIndex = index++; newReply.Answers.Add(newAnswer); } // Create activity var activity = CreateActivity(ActivityType.IdeationReply, user, ideation.Project.Platform); activity.IdeationReply = newReply; _activityManager.AddActivity(activity); // Save everything _unitOfWorkManager.Save(); // Push activity var activityVm = new ActivityViewModel(activity); PushWebsockets(activityVm).Wait(); return(Ok()); }
protected override void Seed(FestispecContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. // context.SaveChanges(); try { var address = new Address { Id = 1, StreetName = "Isolatorweg", HouseNumber = 36, ZipCode = "1014AS", City = "Amsterdam", Country = "Nederland", Latitude = 52.39399f, Longitude = 4.8507514f }; var address2 = new Address { Id = 2, Country = "Duitsland", StreetName = "Flughafen-Ring", HouseNumber = 16, City = "Weeze", ZipCode = "NW47652", Latitude = 51.5924149f, Longitude = 6.1545434f }; var address3 = new Address { Id = 3, City = "Utrecht", Country = "Nederland", HouseNumber = 59, StreetName = "Chopinstraat", ZipCode = "3533EL", Latitude = 52.0857048f, Longitude = 5.08541441f }; var address4 = new Address { City = "Amsterdam", Country = "Nederland", HouseNumber = 14, StreetName = "Lutmastraat", ZipCode = "1072JL", Latitude = 52.350400f, Longitude = 4.892710f }; context.Addresses.AddOrUpdate(address, address2, address3, address4); Employee employee = CreateEmployee(context, address3); var customer = new Customer { Id = 1, CustomerName = "Q-DANCE", KvkNr = 34212891, Address = address, ContactDetails = new ContactDetails { EmailAddress = "*****@*****.**", PhoneNumber = "+31204877300" } }; context.Customers.AddOrUpdate(customer); var now = DateTime.Now; var festival = new Festival { Id = 1, FestivalName = "Q-BASE", Customer = customer, Description = "Nachtfestival over de grens", Address = address2, OpeningHours = new OpeningHours { StartTime = new TimeSpan(now.Hour, now.Minute, now.Second), EndTime = new TimeSpan(8, 0, 0), StartDate = new DateTime(2020, 1, 1), EndDate = new DateTime(2020, 9, 6) } }; context.Festivals.AddOrUpdate(festival); customer.Festivals = new List <Festival> { festival }; context.Customers.AddOrUpdate(customer); var questionnaire = new Questionnaire { Id = 1, Name = "Tester", Festival = festival }; context.Questionnaires.AddOrUpdate(questionnaire); var employeeInspector = new Employee { Id = 2, Iban = "NL01RABO12789410", Name = new FullName { First = "Jan", Last = "Dirksen" }, Account = new Account { Id = 1, // Voorletter + Achternaam + geboortejaar Username = "******", Password = BCrypt.Net.BCrypt.HashPassword("TestWachtwoord"), Role = Role.Inspector }, Address = address4, ContactDetails = new ContactDetails { EmailAddress = "*****@*****.**", PhoneNumber = "+31987654321" }, Certificates = new List <Certificate> { new Certificate { Id = 2, CertificateTitle = "Inspection Certificate", CertificationDate = new DateTime(2019, 3, 4, 00, 00, 00), ExpirationDate = new DateTime(2021, 3, 4, 00, 00, 00) } } }; var plannedInspection = new PlannedInspection { Id = 1, Employee = employeeInspector, Festival = festival, EventTitle = "Inspection " + festival.FestivalName, StartTime = DateTime.Now.Date.Add(new TimeSpan(0, 10, 0, 0)), EndTime = DateTime.Now.Date.Add(new TimeSpan(0, 20, 0, 0)), Questionnaire = questionnaire, }; context.PlannedInspections.AddOrUpdate(plannedInspection); #region DrawQuestion var drawQuestion = new DrawQuestion { Id = 1, PicturePath = "/Uploads/grasso.png", Questionnaire = questionnaire, Contents = "Wat is de kortste looproute van de mainstage naar de nooduitgang?" }; var drawQuestionAnswer = new FileAnswer { Id = 1, Question = drawQuestion, UploadedFilePath = "/Uploads/inspection_adsfadfs.png", PlannedInspection = plannedInspection }; context.Answers.AddOrUpdate(drawQuestionAnswer); context.Questions.AddOrUpdate(drawQuestion); #endregion #region MultipleChoiceQuestion var multipleChoiceQuestion = new MultipleChoiceQuestion { Id = 2, Contents = "Zijn er evacuatieplannen zichtbaar opgesteld?", Options = "Ja~Nee", OptionCollection = new ObservableCollection <StringObject> { new StringObject("Option1") }, Questionnaire = questionnaire }; var multipleChoiceQuestionAnswer = new MultipleChoiceAnswer { Id = 2, MultipleChoiceAnswerKey = 0, PlannedInspection = plannedInspection, Question = multipleChoiceQuestion }; context.Answers.AddOrUpdate(multipleChoiceQuestionAnswer); context.Questions.AddOrUpdate(multipleChoiceQuestion); #endregion #region NumericQuestion var numericQuestion = new NumericQuestion { Id = 3, Contents = "Hoeveel EHBO-posten zijn er aanwezig?", Minimum = 0, Maximum = 99, Questionnaire = questionnaire }; var numericQuestionAnswer = new NumericAnswer { Id = 3, Question = numericQuestion, IntAnswer = 3, PlannedInspection = plannedInspection }; context.Answers.AddOrUpdate(numericQuestionAnswer); context.Questions.AddOrUpdate(numericQuestion); #endregion #region RatingQuestion var ratingQuestion = new RatingQuestion { Id = 4, Contents = "Op een schaal van 1 tot 5, is de beveiliging voldoende aanwezig op het terrein?", HighRatingDescription = "Er is veel beveiliging", LowRatingDescription = "Er is amper beveiliging", Questionnaire = questionnaire }; var ratingQuestionAnswer = new NumericAnswer { Id = 3, Question = numericQuestion, IntAnswer = 4, PlannedInspection = plannedInspection }; context.Answers.AddOrUpdate(ratingQuestionAnswer); context.Questions.AddOrUpdate(ratingQuestion); #endregion #region StringQuestion var stringQuestion = new StringQuestion { Id = 5, Contents = "Geef een korte samenvatting van het vluchtplan.", IsMultiline = true, Questionnaire = questionnaire }; var stringQuestionAnswer = new StringAnswer { Id = 5, Question = stringQuestion, AnswerContents = "In geval van een calamiteit is voor de bezoekers duidelijk te zien dat er vanaf de mainstage al vier vluchtroutes bestaan.", PlannedInspection = plannedInspection }; context.Answers.AddOrUpdate(stringQuestionAnswer); context.Questions.AddOrUpdate(stringQuestion); #endregion #region PictureQuestion var pictureQuestion = new UploadPictureQuestion { Id = 6, Contents = "Plaats een foto van de vluchtroutes op het calamiteitenplan.", Questionnaire = questionnaire }; var pictureQuestionAnswer = new FileAnswer { Id = 6, Question = pictureQuestion, UploadedFilePath = "/uploads/inspection_adsfadfs.png", PlannedInspection = plannedInspection }; context.Answers.AddOrUpdate(pictureQuestionAnswer); context.Questions.AddOrUpdate(pictureQuestion); #endregion #region ReferenceQuestion var referenceQuestion = new ReferenceQuestion { Id = 7, Question = pictureQuestion, Contents = pictureQuestion.Contents, Questionnaire = questionnaire }; var referenceQuestionAnswer = new FileAnswer { Id = 7, Question = referenceQuestion, UploadedFilePath = "/uploads/inspection_eruwioeiruwoio.png", PlannedInspection = plannedInspection }; context.Answers.AddOrUpdate(referenceQuestionAnswer); context.Questions.AddOrUpdate(referenceQuestion); #endregion context.Employees.AddOrUpdate(employeeInspector); context.SaveChanges(); } catch (DbEntityValidationException e) { foreach (DbEntityValidationResult eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (DbValidationError ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
public IActionResult Reply(FormViewModel formVM) { if (!ModelState.IsValid) { return(View(formVM)); } Form form = _formManager.GetForm(formVM.FormId); FormReply reply = new FormReply() { Answers = new List <Answer>(), Email = formVM.Email.Email, Form = form }; int index = 0; foreach (FormQuestionViewModel questionVM in formVM.Questions) { Answer answer; bool isValid = true; switch (questionVM.FieldType) { case FieldType.OpenText: isValid = questionVM.OpenAnswer != null; answer = new OpenTextAnswer() { QuestionIndex = index, OrderIndex = index, Value = questionVM.OpenAnswer }; break; case FieldType.MultipleChoice: isValid = questionVM.MultipleChoiceAnswer.Contains(true); answer = new MultipleChoiceAnswer() { QuestionIndex = index, OrderIndex = index, SelectedChoices = questionVM.MultipleChoiceAnswer.ToList() }; break; case FieldType.DropDown: case FieldType.SingleChoice: case FieldType.Statement: if (questionVM.SingleChoiceAnswer.HasValue) { answer = new SingleChoiceAnswer() { QuestionIndex = index, OrderIndex = index, SelectedChoice = questionVM.SingleChoiceAnswer.Value }; } else { answer = null; isValid = false; } break; default: throw new NotSupportedException("Fieldtype not supported yet"); } if (isValid) { reply.Answers.Add(answer); } index++; } _formManager.AddFormReply(reply); _unitOfWorkManager.Save(); return(RedirectToAction("Confirmation", new { email = reply.Email })); }
private async Task <MultipleChoiceQuestion> CreateMultipleChoiceQuestionAsync(Fixture fixture) { _dbContext.MultipleChoiceQuestions.RemoveRange(_dbContext.MultipleChoiceQuestions); await _dbContext.SaveChangesAsync(); var author = new Author { Name = fixture.Create <string>() }; var authorX = new Author { Name = fixture.Create <string>() }; var authorY = new Author { Name = fixture.Create <string>() }; await _dbContext.Authors.AddRangeAsync(author, authorX, authorY); await _dbContext.SaveChangesAsync(); var quote = new Quote { Content = fixture.Create <string>() }; await _dbContext.Quotes.AddAsync(quote); await _dbContext.SaveChangesAsync(); var multipleChoiceQuestion = new MultipleChoiceQuestion { QuoteId = quote.Id, CorrectAuthorId = author.Id }; await _dbContext.MultipleChoiceQuestions.AddAsync(multipleChoiceQuestion); await _dbContext.SaveChangesAsync(); var answerX = new MultipleChoiceAnswer { MultipleChoiceQuestionId = multipleChoiceQuestion.Id, AuthorChoiceId = authorX.Id }; var answerY = new MultipleChoiceAnswer { MultipleChoiceQuestionId = multipleChoiceQuestion.Id, AuthorChoiceId = authorY.Id }; await _dbContext.MultipleChoiceAnswers.AddRangeAsync(new List <MultipleChoiceAnswer> { answerY, answerX }); await _dbContext.SaveChangesAsync(); return(multipleChoiceQuestion); }