public ActionResult CreatePoll(string question)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();

            if (!String.IsNullOrEmpty(question))
            {
                try
                {
                    Poll poll = new Poll
                    {
                        QuestionText = question,
                        Path = question.ToUrlFormat(),
                        AddedBy = User.Identity.Name,
                        AddedDate = DateTime.Now
                    };

                    dc.Polls.InsertOnSubmit(poll);
                    dc.SubmitChanges();

                    TempData["SuccessMessage"] = "Your poll has been created.";
                    return RedirectToAction("EditPoll", new { pollId = poll.PollID });
                }
                catch (Exception exc)
                {
                    TempData["ErrorMessage"] = exc.Message;
                }
            }

            ViewData["question"] = question;

            ViewData["PageTitle"] = "Create Poll";

            return View("CreatePoll");
        }
 public static void InsertOnSubmit(this DbSet<Poll> source, Poll poll)
 {
     if (poll.PollID == default(int))
     {
         // New entity
         source.Add(poll);
     }
     else
     {
         // Existing entity
         source.Attach(poll);
     }
 }
 public static void DeleteOnSubmit(this DbSet<Poll> source, Poll poll)
 {
     source.Remove(poll);
 }