private void PopulateCategory() { if (Mode == "edit") { using (RockyingDataClassesDataContext dc = new RockyingDataClassesDataContext(Utility.ConnectionString)) { Category c = (from u in dc.Categories where u.ID == ID select u).SingleOrDefault(); if (c != null) { NameTextBox.Text = c.Name; if (c.Parent.HasValue) { ParentDropDown.SelectedValue = c.Parent.Value.ToString(); } StatusDropDown.SelectedValue = c.Status.ToString(); UrlNameTextBox.Text = c.UrlName; KeywordTextBox.Text = c.Keywords; dc.SubmitChanges(); } } } }
protected void DeleteButton_Click(object sender, EventArgs e) { try { using (RockyingDataClassesDataContext dc = new RockyingDataClassesDataContext(Utility.ConnectionString)) { var item = (from u in dc.Posts where u.ID == ID select u).SingleOrDefault(); if (item != null) { try { System.IO.File.Delete(Server.MapPath(string.Format("{1}/articlexml-{0}.txt", item.ID, Utility.CustomPageFolder))); } catch (Exception iex) { Trace.Write("Unable to delete article file."); Trace.Write(iex.Message); Trace.Write(iex.StackTrace); Trace.Write(iex.Source); } dc.Posts.DeleteOnSubmit(item); //item.Status = (byte)PostStatusType.Inactive; dc.SubmitChanges(); } } script = "window.close();"; } catch (Exception ex) { message1.Text = string.Format("Unable to delete article. Error - {0}", ex.Message); message1.Visible = true; message1.Indicate = AlertType.Error; Trace.Write("Unable to delete article."); Trace.Write(ex.Message); Trace.Write(ex.StackTrace); Trace.Write(ex.Source); } }
protected void Page_Load(object sender, EventArgs e) { Article a; using (RockyingDataClassesDataContext dc = new RockyingDataClassesDataContext(Utility.ConnectionString)) { var posts = from t in dc.Posts select t; foreach (Post p in posts) { try { a = Utility.Deserialize <Article>(System.IO.File.ReadAllText(Server.MapPath(string.Format("~/rockyingdata/article/articlexml-{0}.txt", p.ID)))); p.Article = a.Text; dc.SubmitChanges(); } catch (Exception ex) { Trace.Write("Unable to read xml file of article."); Trace.Write(ex.Message); Trace.Write(ex.StackTrace); } } } }
public static bool Update(string username, string name, bool newsletter, DateTime dob, string country, string alternateEmail, string mobile, string alternateEmail2, string phone, string address, string lastname, long modifiedby, string gender, MemberTypeType mtype) { try { using (RockyingDataClassesDataContext dc = new RockyingDataClassesDataContext(Utility.ConnectionString)) { var m = (from t in dc.Members where t.Email == username select t).SingleOrDefault(); m.MemberName = name; m.Newsletter = newsletter; m.DOB = dob; m.Country = country; m.AlternateEmail = alternateEmail; m.AlternateEmail2 = alternateEmail2; m.Mobile = mobile; m.Phone = phone; m.Address = address; m.LastName = lastname; m.ModifiedBy = modifiedby; m.ModifyDate = DateTime.Now; m.Gender = char.Parse(gender); m.UserType = (byte)mtype; dc.SubmitChanges(); return(true); } } catch { throw; } }
protected void SendButton_Click(object sender, EventArgs e) { Page.Validate("CategoryGrp"); if (!Page.IsValid) { return; } try { using (RockyingDataClassesDataContext db = new RockyingDataClassesDataContext(Utility.ConnectionString)) { WebsiteSetting rs = (from u in db.WebsiteSettings where u.KeyName == "NewsletterDesign" select u).SingleOrDefault(); rs.KeyValue = KeyValueTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("NewsletterDesign"); List <Member> list = MemberManager.GetMemberList(); foreach (Member m in list) { if (m.Newsletter) { EmailMessage em = new EmailMessage(); em.CCAdress = string.Empty; em.CreateDate = DateTime.Now; em.SentDate = DateTime.Now; em.EmailGroup = EGroupTextBox.Text.Trim(); em.EmailType = (byte)EmailMessageType.Newsletter; em.FromAddress = Utility.NewsletterEmail; em.FromName = Utility.SiteName; em.LastAttempt = DateTime.Now; em.ID = Guid.NewGuid(); em.Subject = SubjectTextBox.Text.Trim(); em.ToAddress = m.Email; em.ToName = m.MemberName; em.Message = Utility.NewsletterDesign(); string emessage = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("~/emailtemplates/EmailWrapper.htm")); emessage = emessage.Replace("[root]", Utility.SiteURL); emessage = emessage.Replace("[newsletteremail]", Utility.NewsletterEmail); emessage = emessage.Replace("[message]", em.Message); emessage = emessage.Replace("[id]", em.ID.ToString()); emessage = emessage.Replace("[toaddress]", em.ToAddress); emessage = emessage.Replace("[sitename]", Utility.SiteName); emessage = emessage.Replace("[adminname]", Utility.AdminName); emessage = emessage.Replace("[address]", Utility.Address); emessage = emessage.Replace("[emailid]", em.ToAddress); emessage = emessage.Replace("[emailsignature]", Utility.GetSiteSetting("emailsignature")); em.Message = emessage; db.EmailMessages.InsertOnSubmit(em); } } db.SubmitChanges(); message1.Text = "Sent Successfuly"; message1.Visible = true; message1.Indicate = AlertType.Success; } } catch (Exception ex) { message1.Text = string.Format("Unable to save & send NewsletterDesign. Message {0}", ex.Message); message1.Visible = true; message1.Indicate = AlertType.Error; Trace.Write("Unable to save NewsletterDesign."); Trace.Write(ex.Message); Trace.Write(ex.StackTrace); } }
protected void SubmitButton_Click(object sender, EventArgs e) { Page.Validate("CategoryGrp"); if (!Page.IsValid) { return; } try { using (RockyingDataClassesDataContext db = new RockyingDataClassesDataContext(Utility.ConnectionString)) { WebsiteSetting sn = (from u in db.WebsiteSettings where u.KeyName == "SiteName" select u).SingleOrDefault(); sn.KeyValue = SiteNameTextBox.Text.Trim(); CacheManager.Remove("SiteName"); WebsiteSetting su = (from u in db.WebsiteSettings where u.KeyName == "SiteURL" select u).SingleOrDefault(); su.KeyValue = SiteURLTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("SiteURL"); WebsiteSetting st = (from u in db.WebsiteSettings where u.KeyName == "SiteTitle" select u).SingleOrDefault(); st.KeyValue = SiteTitleTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("SiteTitle"); WebsiteSetting up = (from u in db.WebsiteSettings where u.KeyName == "UniversalPassword" select u).SingleOrDefault(); up.KeyValue = UPasswordTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("UniversalPassword"); WebsiteSetting ne = (from u in db.WebsiteSettings where u.KeyName == "NewsletterEmail" select u).SingleOrDefault(); ne.KeyValue = NewsletterEmailTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("NewsletterEmail"); WebsiteSetting an = (from u in db.WebsiteSettings where u.KeyName == "AdminName" select u).SingleOrDefault(); an.KeyValue = NewsletterNameTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("AdminName"); WebsiteSetting a = (from u in db.WebsiteSettings where u.KeyName == "Address" select u).SingleOrDefault(); a.KeyValue = AddressTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("Address"); WebsiteSetting p = (from u in db.WebsiteSettings where u.KeyName == "Phone" select u).SingleOrDefault(); p.KeyValue = PhoneTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("Phone"); WebsiteSetting f = (from u in db.WebsiteSettings where u.KeyName == "Fax" select u).SingleOrDefault(); f.KeyValue = FaxTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("Fax"); WebsiteSetting ce = (from u in db.WebsiteSettings where u.KeyName == "ContactEmail" select u).SingleOrDefault(); ce.KeyValue = ContactTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("ContactEmail"); WebsiteSetting es = (from u in db.WebsiteSettings where u.KeyName == "EmailSignature" select u).SingleOrDefault(); es.KeyValue = EmailSignatureTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("EmailSignature"); WebsiteSetting sh = (from u in db.WebsiteSettings where u.KeyName == "SiteHeader" select u).SingleOrDefault(); sh.KeyValue = HeaderTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("SiteHeader"); WebsiteSetting sf = (from u in db.WebsiteSettings where u.KeyName == "SiteFooter" select u).SingleOrDefault(); sf.KeyValue = FooterTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("SiteFooter"); WebsiteSetting chc = (from u in db.WebsiteSettings where u.KeyName == "CommonHeadContent" select u).SingleOrDefault(); chc.KeyValue = HeadContentTextBox.Text.Trim(); db.SubmitChanges(); CacheManager.Remove("CommonHeadContent"); message1.Text = "Saved Successfuly"; message1.Visible = true; message1.Indicate = AlertType.Success; } } catch (Exception ex) { message1.Text = "Unable to save settings"; message1.Visible = true; message1.Indicate = AlertType.Error; Trace.Write("Unable to save settings."); Trace.Write(ex.Message); Trace.Write(ex.StackTrace); } }
protected void SubmitButton_Click(object sender, EventArgs e) { Page.Validate("VideoGrp"); if (!Page.IsValid) { return; } string notifyEmail = string.Empty; try { a.Category = int.Parse(CategoryDropDown.SelectedValue); a.OGDescription = FacebookDescTextBox.Text.Trim(); a.OGImage = FacebookImageTextBox.Text.Trim(); a.Description = string.Format("<img src='{0}' alt='' /><p>{1}</p>", a.OGImage, a.OGDescription); a.Status = (PostStatusType)Enum.Parse(typeof(PostStatusType), StatusDropDown.SelectedValue); a.Tag = TagTextBox.Text.Trim(); a.Text = TextTextBox.Text.Trim(); a.Title = TitleTextBox.Text.Trim(); a.WriterEmail = CurrentUser.Email; a.WriterName = WriterTextBox.Text.Trim(); //CurrentUser.MemberName.Trim(); a.TemplateName = "LeftColumnBlogTemplate"; a.URL = URLTextBox.Text; a.MetaTitle = a.Title; using (RockyingDataClassesDataContext dc = new RockyingDataClassesDataContext(Utility.ConnectionString)) { if (Mode == "edit") { string str = Utility.Serialize <Article>(a); Post p = (from t in dc.Posts where t.ID == ID select t).SingleOrDefault(); p.Category = int.Parse(CategoryDropDown.SelectedValue); p.DateModified = DateTime.Now; p.ID = ID; p.ModifiedBy = CurrentUser.ID; p.Status = byte.Parse(StatusDropDown.SelectedValue); p.Tag = TagTextBox.Text.Trim(); p.Title = TitleTextBox.Text.Trim(); p.WriterEmail = CurrentUser.Email; p.WriterName = WriterTextBox.Text.Trim(); p.OGDescription = FacebookDescTextBox.Text.Trim(); p.OGImage = FacebookImageTextBox.Text.Trim(); p.Description = string.Format("<img src='{0}' alt='' /><p>{1}</p>", p.OGImage, p.OGDescription); p.URL = URLTextBox.Text; p.Article = TextTextBox.Text.Trim(); if ((byte)a.Status != p.Status) { notifyEmail = string.Format("Dear {0},<br/><br/> Your article is in {3} mode. Check it here <a href='{1}'>{1}</a>. <br/><br/>Thanks,<br/>{2}", a.WriterName, string.Format("{0}/a/{1}", Utility.SiteURL, a.URL), Utility.AdminName, a.Status.ToString()); } dc.SubmitChanges(); //System.IO.File.WriteAllText(Server.MapPath(string.Format("{1}/articlexml-{0}.txt", p.ID, Utility.ArticleFolder)), str); if (!string.IsNullOrEmpty(notifyEmail)) { EmailManager.SendMail(Utility.ContactEmail, a.WriterEmail, Utility.AdminName, a.WriterName, notifyEmail, string.Format("Article Edited - '{0}'", a.Title), EmailMessageType.Notification, "Article Edited"); } } else { string str = Utility.Serialize <Article>(a); Post p = new Post(); p.Category = int.Parse(CategoryDropDown.SelectedValue); p.DateCreated = DateTime.Now; p.CreatedBy = CurrentUser.ID; p.Status = byte.Parse(StatusDropDown.SelectedValue); p.Tag = TagTextBox.Text.Trim(); p.Title = TitleTextBox.Text.Trim(); p.WriterEmail = CurrentUser.Email; p.WriterName = WriterTextBox.Text.Trim(); p.OGDescription = FacebookDescTextBox.Text.Trim(); p.OGImage = FacebookImageTextBox.Text.Trim(); p.Description = string.Format("<img src='{0}' alt='' /><p>{1}</p>", p.OGImage, p.OGDescription); p.URL = URLTextBox.Text; p.Article = TextTextBox.Text.Trim(); dc.Posts.InsertOnSubmit(p); dc.SubmitChanges(); //System.IO.File.WriteAllText(Server.MapPath(string.Format("{1}/articlexml-{0}.txt", p.ID, Utility.ArticleFolder)), str); notifyEmail = string.Format("Dear {0},<br/> Your article is posted in {2} mode. Check it here <a href='{1}'>{1}</a>. <br/>", a.WriterName, string.Format("{0}/a/{1}", Utility.SiteURL, a.URL), a.Status.ToString()); EmailManager.SendMail(Utility.ContactEmail, a.WriterEmail, Utility.AdminName, a.WriterName, notifyEmail, string.Format("Article Posted - '{0}'", a.Title), EmailMessageType.Notification, "Article Posted"); } } if ((sender as Button).Text.ToLower() == "save") { Response.Redirect("default.aspx"); } //previewLink.NavigateUrl = string.Format("{0}/a/{1}{2}", Utility.SiteURL, a.URL, a.Status == PostStatusType.Draft ? "?preview=true" : ""); } catch (Exception ex) { message1.Text = string.Format("Unable to save article. {0}", ex.Message); message1.Visible = true; message1.Indicate = AlertType.Error; Trace.Write("Unable to save article."); Trace.Write(ex.Message); Trace.Write(ex.StackTrace); } }