public async Task UpdateQuestion(Model.Questions model) { model.UserInfoID = model.QuestionUserInfo.UserID; UpdateQuestionUserInfo(model.QuestionUserInfo); if (model.Addition != null) { model.AdditionID = model.Addition.QID; UpdateAddition(model.Addition); } await QueryQuestion(model.Qid).ContinueWith(async(results) => { if (results.Result == null) { try { await db.InsertAsync(model); } catch (Exception ex) { Log.SaveLog("UpdateQuestion.Insert", ex); } } else { try { await db.UpdateAsync(model); } catch (Exception ex) { Log.SaveLog("UpdateQuestion.Update", ex); } } }); }
private void cbQuestions_SelectionChanged(object sender, SelectionChangedEventArgs e) { Model.Questions que = (Model.Questions)((ComboBox)sender).SelectedItem; if (que == null) { tbxQuestionContent.IsEnabled = false; tbxQuestionContent.Text = string.Empty; wpListAnswer.Children.RemoveRange(0, wpListAnswer.Children.Count); SaveButton.IsEnabled = false; return; } tbxQuestionContent.IsEnabled = true; SaveButton.IsEnabled = true; tbxQuestionContent.Text = que.QuestionContent; foreach (var item in model.Answers) { if (item.QuestionId == que.QuestionId) { WrapPanel wp = new WrapPanel(); wp.Orientation = Orientation.Horizontal; Label lb = new Label() { Content = "Ответ " + (wpListAnswer.Children.Count + 1) + ": " }; Label idLabel = new Label() { Content = item.AnswerId, IsEnabled = false, Name = "id" }; TextBox tb = new TextBox() { Width = 150, Name = "tb" + (wpListAnswer.Children.Count + 1) }; tb.Text = item.Content; CheckBox cb = new CheckBox() { IsChecked = false }; cb.IsChecked = item.IsCorrect; wp.Children.Add(lb); wp.Children.Add(idLabel); wp.Children.Add(tb); wp.Children.Add(cb); wpListAnswer.Children.Add(wp); } } }
public async Task <ActionResult> Post([FromBody] Model.Questions question) { var quiz = _context.quizes.SingleOrDefault(q => q.Id == question.quizId); /* * var quiz = _context.quizes.SingleOrDefault(q => q.Id == question.quizId); * if(quiz==null){ * return NotFound(); * } * if(! ModelState.IsValid){ * return BadRequest(); * } */ if (quiz == null) { return(NotFound()); } _context.Add(question); await _context.SaveChangesAsync(); return(Ok(question)); }
private void cbQuestions_SelectionChanged(object sender, SelectionChangedEventArgs e) { Model.Questions que = (Model.Questions)((ComboBox)sender).SelectedItem; if (que == null) { return; } expQuestion.Header = que.QuestionContent; WrapPanel panel = new WrapPanel(); panel.Orientation = Orientation.Vertical; List <Model.Answers> ans = model.Answers.Where(p => p.QuestionId == que.QuestionId).ToList(); foreach (var item in ans) { Label label = new Label(); label.Content = item.Content; if (item.IsCorrect == false) { label.Foreground = Brushes.Red; } else { label.Foreground = Brushes.Green; } panel.Children.Add(label); } expQuestion.Content = panel; expQuestion.IsEnabled = true; }