//[HttpPost] //public ActionResult Poll(string shortURL, int Answer) //{ // Question q = new Question(); // q = db.Questions.First(x => x.ShortURL == shortURL); // Answer a = new Answer(); // a = db.Answers.First(x => x.AnswerID == Answer); // a.Count = a.Count + 1; // db.SaveChanges(); // return RedirectToAction("PollResults", new { shortUrl = q.ShortURL }); //} //public ActionResult Poll(string shortURL) //{ // PollViewModel pvm = new PollViewModel(); // Question q = new Question(); // q = db.Questions.First(x => x.ShortURL == shortURL); // pvm.Question = q; // pvm.Answers = db.Answers.Where(x => x.QuestionID == q.QuestionID).ToArray(); // return View(pvm); //} public ActionResult Poll(string shortURL) { if (!string.IsNullOrEmpty(shortURL)) { AllPollsViewModel allpolls = new AllPollsViewModel(); List <Answer> temp = new List <Answer>(); allpolls.Questions = db.Questions.Where(q => q.ShortURL == shortURL && q.Active == true).ToArray(); foreach (var q in allpolls.Questions) { temp.AddRange(db.Answers.Where(a => a.QuestionID == q.QuestionID).ToList()); } allpolls.Answers = temp.ToArray(); return(View(allpolls)); } return(RedirectToAction("Index")); }
public ActionResult ManagePolls() { if (User.Identity.IsAuthenticated) { User u = db.Users.First(x => x.Email == User.Identity.Name); AllPollsViewModel allpolls = new AllPollsViewModel(); List <Answer> temp = new List <Answer>(); allpolls.Questions = db.Questions.Where(q => q.CreatedByUserID == u.UserID).ToArray(); foreach (var q in allpolls.Questions) { temp.AddRange(db.Answers.Where(a => a.QuestionID == q.QuestionID).ToList()); } allpolls.Answers = temp.ToArray(); return(View(allpolls)); } return(RedirectToAction("Index")); }