public ActionResult Submit(int questionId, string body) { if (GetCurrentUser() == null) { // todo - handle casual user throw new Exception("Must be signed in to post answers"); } var now = DateTime.Now; var answer = new Answer {Body = body, QuestionId = questionId, Author = GetCurrentUser(), CreatedDate = now, LastRelatedUser = GetCurrentUser(), UpdateDate = now}; _answersRepository.Save(answer); return RedirectToAction("Details", "Question", new { id = questionId}); }
private void AddAnswers() { for (int i = 0; i < 10; ++i) { int questionId = _random.Next(_questions.Count) + 1; int authorId = _random.Next(_users.Count) + 1; var author = new User { Id = authorId }; var date = GetRandomDate(); var answer = new Answer { Author = author, Body = RandomText(20), CreatedDate = date, LastRelatedUser = author, QuestionId = questionId, UpdateDate = date, }; _answers.Add(answer); _answersRepository.Save(answer); } }
public RichAnswer(Answer answer, VoteType? currentUsersVote) { Answer = answer; CurrentUserVote = currentUsersVote; }
private void CreateData() { _questionAuthor = UserFactory.CreateUser(); _question = SaveQuestion(_questionAuthor); for (int i = 0; i < 5; ++i) { var answer = new Answer { Author = _questionAuthor, Body = i.ToString(), CreatedDate = DateTime.Now, LastRelatedUser = _questionAuthor, QuestionId = _question.Id, UpdateDate = DateTime.Now }; _answersRepository.Save(answer); _answers.Add(answer); // add i up-votes for answer i for (int j = 0; j < i; ++j) { var voter = UserFactory.CreateUser(); AnswerVoteRepository.CreateOrUpdateVote(voter, answer, VoteType.ThumbUp); } } }