public ActionResult AnswerToQuestion(AnswerModel answerModel) { if (ModelState.IsValid) { var userName = this.User.Identity.Name; var user = this.Data.Users.All().FirstOrDefault(u => u.UserName == userName); var question = this.Data.Questions.All().FirstOrDefault(q => q.QuestionId == answerModel.QuestionId); var newAnswer = new Answer() { IsReported = false, Comment = answerModel.Comment, User = user, Question = question, DateAnswered = DateTime.Now, }; this.Data.Answers.Add(newAnswer); this.Data.SaveChanges(); user.Points =+ PointsForAnswer; this.Data.SaveChanges(); return View("TakeQuestion", new AnswerModel()); } return View("TakeQuestion", answerModel); }
private static bool DoesUserHavePermissionsToVote(string currenUserId, Answer answer) { var id = answer.Question.Creator.Id; return currenUserId == id; }
public ActionResult Edit(AnswerModel answer) { if (ModelState.IsValid) { var editedAnswer = new Answer() { AnswerId = answer.Id, Comment = answer.Text, DateAnswered = answer.AnsweredDate, IsReported = answer.IsReported, }; this.Data.Answers.Update(editedAnswer); this.Data.SaveChanges(); return RedirectToAction("Index"); } return View(answer); }