public ActionResult CreateNewsletter(string subject, string body)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();

            if (!String.IsNullOrEmpty(subject) && !String.IsNullOrEmpty(body))
            {
                Newsletter newsletter = new Newsletter()
                {
                    AddedDate = DateTime.Now,
                    AddedBy = User.Identity.Name,
                    Status = "Queued",
                    Subject = subject,
                    HtmlBody = body,
                    PlainTextBody = body
                };

                dc.Newsletters.InsertOnSubmit(newsletter);
                dc.SubmitChanges();

                Thread thread = new Thread(new ParameterizedThreadStart(SendNewsletter));
                thread.Priority = ThreadPriority.BelowNormal;
                thread.Start(new object[] { newsletter, dc });

                return RedirectToAction("ManageNewsletters");
            }

            ViewData["PageTitle"] = "Create Newsletter";
            return View(new Newsletter());
        }
 public static void InsertOnSubmit(this DbSet<Newsletter> source, Newsletter newsletter)
 {
     if (newsletter.NewsletterID == default(int))
     {
         // New entity
         source.Add(newsletter);
     }
     else
     {
         // Existing entity
         source.Attach(newsletter);
     }
 }
 public static void DeleteOnSubmit(this DbSet<Newsletter> source, Newsletter newsletter)
 {
     source.Remove(newsletter);
 }