Ejemplo n.º 1
0
 public Answer(User author, string body, Question question, bool accepted = false)
     : base(author, body)
 {
     this.Question = question;
     this.Accepted = accepted;
 }
Ejemplo n.º 2
0
        public ActionResult Create(QuestionModel question)
        {
            if (ModelState.IsValid)
            {
                string[] seperatedTags = question.Tags.Split(new[] { ' ', ',', '.' }, StringSplitOptions.RemoveEmptyEntries);
                List<Tag> tags = new List<Tag>(seperatedTags.Length);
                foreach (string tag in seperatedTags)
                {
                    Tag t = dataContext.Tags.FirstOrDefault(a => a.Name.Equals(tag, StringComparison.OrdinalIgnoreCase));
                    if (t == null)
                    {
                        t = new Tag(tag, null, ControllerHelper.GetAuthenticatedUser(dataContext));
                    }
                    tags.Add(t);
                }

                Question q = new Question(ControllerHelper.GetAuthenticatedUser(dataContext), question.Body, question.Title, tags);

                dataContext.Questions.Add(q);
                dataContext.SaveChanges();
                return RedirectToAction("Question", new { id = q.Id });
            }
            else
            {
                return View();
            }
        }