public ActionResult Create(Answer answer, FormCollection form) { answer.Date = DateTime.Now; String u = membership.LoggedInUser(); answer.UserId = context.Users.Single(x => x.Username == u).UserId; answer.QuestionId = Convert.ToInt32(form["answer_QuestionId"]); Question findQ = context.Questions.SingleOrDefault(x => x.QuestionId == answer.QuestionId); if (answer.Content != null && findQ != null) { if (answer.Content.Length > 5) { context.Answers.Add(answer); context.SaveChanges(); /* foreach (User userX in findQ.Subscribers.ToList()) { // send notification to user } */ return RedirectToAction("Details/" + answer.QuestionId, "Questions"); } } ViewBag.PossibleUsers = context.Users; ViewBag.PossibleQuestions = context.Questions; return RedirectToAction("Details/" + answer.QuestionId, "Questions"); }
public ActionResult Edit(Answer answer) { Answer a = context.Answers.Single(x => x.AnswerId == answer.AnswerId); if (answer.Content != null && answer.Content.Length > 5) { answer.UserId = a.UserId; answer.Date = a.Date; answer.QuestionId = a.QuestionId; answer.Author = a.Author; answer.Question = a.Question; context.Entry(a).CurrentValues.SetValues(answer); context.SaveChanges(); return RedirectToAction("Details/" + answer.QuestionId, "Questions"); } ViewBag.PossibleUsers = context.Users; ViewBag.PossibleQuestions = context.Questions; return View(answer); }