Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
 public static void DeleteOnSubmit(this DbSet<Poll> source, Poll poll)
 {
     source.Remove(poll);
 }