private void GetData()
 {
     string SaveTheDateConnection = ConfigurationManager.ConnectionStrings["iMascotConnectionString"].ConnectionString;
     using (iMascotModelDataContext SaveTheDateDB = new iMascotModelDataContext(SaveTheDateConnection))
     {
         GridView1.DataSource = SaveTheDateDB.PageContents;
         GridView1.DataBind();
     }
 }
 private void GetPageContents()
 {
     string iMascotConnection = ConfigurationManager.ConnectionStrings["iMascotConnectionString"].ConnectionString;
     using (iMascotModelDataContext SaveTheDateDB = new iMascotModelDataContext(iMascotConnection))
     {
         var content = SaveTheDateDB.PageContents.FirstOrDefault(something => something.PageName == Page.Title);
         if (content != null)
             this.PageContents.Text = content.Content;
     }
 }
 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     string ItemID = GridView1.DataKeys[e.RowIndex].Values["ContentID"].ToString();
     string SaveTheDateConnection = ConfigurationManager.ConnectionStrings["iMascotConnectionString"].ConnectionString;
     using (iMascotModelDataContext SaveTheDateDB = new iMascotModelDataContext(SaveTheDateConnection))
     {
         var Item = SaveTheDateDB.PageContents.FirstOrDefault(ab => ab.ContentID.ToString() == ItemID);
         SaveTheDateDB.PageContents.DeleteOnSubmit(Item);
         SaveTheDateDB.SubmitChanges();
         GridView1.DataSource = SaveTheDateDB.PageContents;
         GridView1.DataBind();
     }
 }
        private void GetData(int TemplateID)
        {
            using (iMascotModelDataContext SaveTheDateDB = new iMascotModelDataContext(SaveTheDateConnection))
            {
                SaveTheDateDB.ObjectTrackingEnabled = false;

                var Item = SaveTheDateDB.EmailTemplates.FirstOrDefault(ab => ab.TemplateID == TemplateID);
                if (Item != null)
                {
                    DropDownList1.Items.FindByValue(TemplateID.ToString()).Selected = true;
                    txtMailSubject.Text = Item.MailSubject;
                    CKEditor1.Text = Item.MailBody;
                }
                else
                {
                    txtMailSubject.Text = string.Empty;
                    CKEditor1.Text = string.Empty;
                }
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     ItemID = Request.QueryString["ItemId"];
     if (!Page.IsPostBack)
     {
         if (!string.IsNullOrEmpty(ItemID))
         {
             using (iMascotModelDataContext SaveTheDateDB = new iMascotModelDataContext(SaveTheDateConnection))
             {
                 SaveTheDateDB.ObjectTrackingEnabled = false;
                 var Item = SaveTheDateDB.PageContents.FirstOrDefault(ab => ab.ContentID.ToString() == ItemID);
                 if (Item != null)
                 {
                     txtPageTitle.Text = Item.PageName;
                     CKEditor1.Text = Item.Content;
                 }
             }
         }
     }
 }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(ItemID))
         return;
     using (iMascotModelDataContext SaveTheDateDB = new iMascotModelDataContext(SaveTheDateConnection))
     {
         var Item = SaveTheDateDB.PageContents.FirstOrDefault(ab => ab.ContentID.ToString() == ItemID);
         if (Item == null)
         {
             PageContent pageCont = new PageContent { ContentID = Guid.NewGuid(), PageName = txtPageTitle.Text, Content = CKEditor1.Text };
             SaveTheDateDB.PageContents.InsertOnSubmit(pageCont);
         }
         else
         {
             Item.Content = CKEditor1.Text;
             Item.PageName = txtPageTitle.Text;
         }
         SaveTheDateDB.SubmitChanges();
     }
     Response.Redirect("PageList.aspx");
 }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     using (iMascotModelDataContext SaveTheDateDB = new iMascotModelDataContext(SaveTheDateConnection))
     {
         var Item = SaveTheDateDB.EmailTemplates.FirstOrDefault(ab => ab.TemplateID == int.Parse(DropDownList1.SelectedValue));
         if (Item == null)
         {
             Model.EmailTemplate emailTemplate = new Model.EmailTemplate
                                                     {
                                                         TemplateID = int.Parse(DropDownList1.SelectedValue),
                                                         MailSubject = txtMailSubject.Text,
                                                         MailBody = CKEditor1.Text
                                                     };
             SaveTheDateDB.EmailTemplates.InsertOnSubmit(emailTemplate);
         }
         else
         {
             Item.MailBody = CKEditor1.Text;
             Item.MailSubject = txtMailSubject.Text;
         }
         SaveTheDateDB.SubmitChanges();
     }
 }
 private void DeleteGuest(string[] UserIDs)
 {
     string SaveTheDateConnection = ConfigurationManager.ConnectionStrings["iMascotConnectionString"].ConnectionString;
     using (iMascotModelDataContext SaveTheDateDB = new iMascotModelDataContext(SaveTheDateConnection))
     {
         foreach (string UserId in UserIDs)
         {
             if (!string.IsNullOrEmpty(UserId))
             {
                 var Item = SaveTheDateDB.Guests.FirstOrDefault(ab => ab.UserId.ToString() == UserId);
                 var MemberData = SaveTheDateDB.aspnet_Users.FirstOrDefault(ab => ab.UserId.ToString() == UserId);
                 SaveTheDateDB.Guests.DeleteOnSubmit(Item);
                 SaveTheDateDB.SubmitChanges();
                 Membership.DeleteUser(MemberData.UserName, true);
             }
         }
     }
     GetData();
 }
        private void SendMail(string[] UserIDs)
        {
            string SaveTheDateConnection = ConfigurationManager.ConnectionStrings["iMascotConnectionString"].ConnectionString;
            using (iMascotModelDataContext SaveTheDateDB = new iMascotModelDataContext(SaveTheDateConnection))
            {
                var templateInfo = SaveTheDateDB.EmailTemplates.FirstOrDefault(ab => ab.TemplateID == 1);
                if (templateInfo == null)
                {
                    return;
                }
                string MailSubject = templateInfo.MailSubject ;

                foreach (string UserId in UserIDs)
                {
                    if (!string.IsNullOrEmpty(UserId))
                    {
                        Guid providerUserKey = new Guid(UserId);
                        MembershipUser user = Membership.GetUser(providerUserKey);

                        var usersToken = from ab in SaveTheDateDB.MailTokens
                                         where ab.UserId == providerUserKey
                                         select ab;
                        SaveTheDateDB.MailTokens.DeleteAllOnSubmit(usersToken);

                        SaveTheDateDB.SubmitChanges();
                        MailToken mtoken = new MailToken();
                        mtoken.UserId = providerUserKey;
                        mtoken.UserName = user.UserName;
                        mtoken.EmailToken = Guid.NewGuid();
                        SaveTheDateDB.MailTokens.InsertOnSubmit(mtoken);
                        SaveTheDateDB.SubmitChanges();
                        MailMessage msg = new MailMessage();
                        string MailBody = templateInfo.MailBody.Replace("[!UserName]", user.UserName).Replace("[!Url]" , "<a href=\"" + BaseVirtualAppPath +  "/ResetPassword.aspx?MailToken=" + mtoken.EmailToken.ToString() + "\">here</a>");
                        msg.To.Add(user.Email);
                        msg.Subject = MailSubject.Trim();
                        msg.IsBodyHtml = true;
                        msg.Body = MailBody;
                        SmtpClient smtp = new SmtpClient();
                        smtp.EnableSsl = true;
                        smtp.Send(msg);
                       var userInfo =  SaveTheDateDB.Guests.First(ab => ab.UserId.ToString() == UserId);
                       userInfo.InvitationMail = DateTime.Now;
                       SaveTheDateDB.SubmitChanges();

                    }
                }
            }
        }