public LongAnswerForPresentation(LongAnswer question, bool answerTime, bool showAnswer) { this.answerTime = answerTime; this.showAnswer = showAnswer; var ans = question.Answer; var uAns = question.UserAnswer; InitializeComponent(); if (answerTime) { txtAnswer.Text = uAns; txtAnswer.ReadOnly = false; if (showAnswer) { txtAnswer.ReadOnly = true; var lbl = new Label(); lbl.Width = flowLayoutPanel1.Width; lbl.Text = ans; lbl.AutoSize = true; flowLayoutPanel1.Controls.Add(lbl); } } else { txtAnswer.Visible = false; var lbl = new Label(); lbl.Width = flowLayoutPanel1.Width; lbl.Text = ans; lbl.AutoSize = true; flowLayoutPanel1.Controls.Add(lbl); } }
private bool RegisterLongAnswerQuestion(irQmDbContext db) { if (string.IsNullOrEmpty(ucLongAnswer1.Answer)) { lblMessage.Text = "جواب مشخص نشده است"; lblMessage.ForeColor = Color.Red; return(false); } var q = new LongAnswer(); q.Id = Guid.NewGuid().ToString(); q.Face = rbFace.Rtf; q.RegisterTime = DateTime.UtcNow; var tagsInBox = tagsBox1.Tags; var tags = db.Tags.Select(t => t.Value).ToArray(); foreach (var tg in tagsInBox.Where(t => !(tags.Contains(t)))) { var tag = new Tag(); tag.Value = tg; db.Tags.Add(tag); } foreach (var t in tagsInBox) { TagInQuestion <LongAnswer> tagInQuestion = new TagInQuestion <LongAnswer>(); tagInQuestion.QuestionId = q.Id; tagInQuestion.TagId = t; db.TagInLongAnswer.Add(tagInQuestion); } q.Answer = ucLongAnswer1.Answer; q.LessonName = comboLesson.Text.Trim(); q.CreatorUserId = Globals.CurrentUser.UserId; db.LongAnswerQuestions.Add(q); db.SaveChanges(); ucLongAnswer1.New(); return(true); }