PageRenderTime 47ms CodeModel.GetById 34ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/BlogEngine/BlogEngine.NET/admin/Settings/Comments.aspx.cs

#
C# | 88 lines | 65 code | 12 blank | 11 comment | 4 complexity | 43a69fa095f82bdb3dbce111dccfa072 MD5 | raw file
 1namespace admin.Comments
 2{
 3    using System;
 4    using System.Data;
 5    using System.Web.UI.WebControls;
 6    using BlogEngine.Core;
 7    using BlogEngine.Core.Web.Extensions;
 8    using App_Code;
 9
10    public partial class Settings : System.Web.UI.Page
11    {
12        protected void Page_Load(object sender, EventArgs e)
13        {
14            WebUtils.CheckRightsForAdminSettingsPage(false);
15
16            if (!IsPostBack)
17            {
18                BindSettings();
19            }
20
21            Page.MaintainScrollPositionOnPostBack = true;
22            Page.Title = Resources.labels.comments;
23
24            btnSave.Click += btnSave_Click;
25            btnSave.Text = Resources.labels.saveSettings;
26        }
27
28        private void BindSettings()
29        {
30            //-----------------------------------------------------------------------
31            // Bind Comments settings
32            //-----------------------------------------------------------------------
33            cbEnableComments.Checked = BlogSettings.Instance.IsCommentsEnabled;
34            cbEnableCommentNesting.Checked = BlogSettings.Instance.IsCommentNestingEnabled;
35            cbEnableCountryInComments.Checked = BlogSettings.Instance.EnableCountryInComments;
36            cbEnableWebsiteInComments.Checked = BlogSettings.Instance.EnableWebsiteInComments;
37            cbEnableCoComment.Checked = BlogSettings.Instance.IsCoCommentEnabled;
38            cbShowLivePreview.Checked = BlogSettings.Instance.ShowLivePreview;
39            cbShowPingBacks.Checked = BlogSettings.Instance.ShowPingBacks;
40            ddlCloseComments.SelectedValue = BlogSettings.Instance.DaysCommentsAreEnabled.ToString();
41            cbEnableCommentsModeration.Checked = BlogSettings.Instance.EnableCommentsModeration;
42            rblAvatar.SelectedValue = BlogSettings.Instance.Avatar;
43            ddlCommentsPerPage.SelectedValue = BlogSettings.Instance.CommentsPerPage.ToString();
44
45            // disqus
46            cbEnableDisqus.Checked = BlogSettings.Instance.ModerationType == BlogSettings.Moderation.Disqus;
47            string discusName = "YourDisqusWebsite";
48            if (BlogSettings.Instance.DisqusWebsiteName != null)
49                discusName = BlogSettings.Instance.DisqusWebsiteName;
50
51            txtDisqusName.Text = discusName;
52            cbDisqusDevMode.Checked = BlogSettings.Instance.DisqusDevMode;
53            cbDisqusAddToPages.Checked = BlogSettings.Instance.DisqusAddCommentsToPages;
54        }
55
56        protected void btnSave_Click(object sender, EventArgs e)
57        {
58            //-----------------------------------------------------------------------
59            // Set Comments settings
60            //-----------------------------------------------------------------------
61            BlogSettings.Instance.IsCommentsEnabled = cbEnableComments.Checked;
62            BlogSettings.Instance.IsCommentNestingEnabled = cbEnableCommentNesting.Checked;
63            BlogSettings.Instance.EnableCountryInComments = cbEnableCountryInComments.Checked;
64            BlogSettings.Instance.EnableWebsiteInComments = cbEnableWebsiteInComments.Checked;
65            BlogSettings.Instance.IsCoCommentEnabled = cbEnableCoComment.Checked;
66            BlogSettings.Instance.ShowLivePreview = cbShowLivePreview.Checked;
67            BlogSettings.Instance.ShowPingBacks = cbShowPingBacks.Checked;
68
69            BlogSettings.Instance.DaysCommentsAreEnabled = int.Parse(ddlCloseComments.SelectedValue);
70            BlogSettings.Instance.EnableCommentsModeration = cbEnableCommentsModeration.Checked;
71            BlogSettings.Instance.Avatar = rblAvatar.SelectedValue;
72            BlogSettings.Instance.CommentsPerPage = int.Parse(ddlCommentsPerPage.SelectedValue);
73
74            // disqus 
75            BlogSettings.Instance.ModerationType = cbEnableDisqus.Checked ? BlogSettings.Moderation.Disqus : BlogSettings.Moderation.Auto;
76            BlogSettings.Instance.DisqusWebsiteName = txtDisqusName.Text.Length > 250 ? txtDisqusName.Text.Substring(0, 250) : txtDisqusName.Text;
77            BlogSettings.Instance.DisqusDevMode = cbDisqusDevMode.Checked;
78            BlogSettings.Instance.DisqusAddCommentsToPages = cbDisqusAddToPages.Checked;
79
80            //-----------------------------------------------------------------------
81            //  Persist settings
82            //-----------------------------------------------------------------------
83            BlogSettings.Instance.Save();
84
85            Response.Redirect(Request.RawUrl, true);
86        }
87    }
88}