PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/widgets/RecentPosts/edit.ascx.cs

#
C# | 63 lines | 36 code | 12 blank | 15 comment | 2 complexity | 832834b96ec4f0bdf204cd08b06bff7b MD5 | raw file
 1// --------------------------------------------------------------------------------------------------------------------
 2// <summary>
 3//   The widgets_ recent posts_edit.
 4// </summary>
 5// --------------------------------------------------------------------------------------------------------------------
 6
 7namespace Widgets.RecentPosts
 8{
 9    using System;
10    using System.Web;
11
12    using App_Code.Controls;
13    using BlogEngine.Core;
14
15    /// <summary>
16    /// The widgets_ recent posts_edit.
17    /// </summary>
18    public partial class Edit : WidgetEditBase
19    {
20        #region Public Methods
21
22        /// <summary>
23        /// Saves this the basic widget settings such as the Title.
24        /// </summary>
25        public override void Save()
26        {
27            var settings = this.GetSettings();
28            settings["numberofposts"] = this.txtNumberOfPosts.Text;
29            settings["showcomments"] = this.cbShowComments.Checked.ToString();
30            settings["showrating"] = this.cbShowRating.Checked.ToString();
31            this.SaveSettings(settings);
32            Blog.CurrentInstance.Cache.Remove("widget_recentposts");
33        }
34
35        #endregion
36
37        #region Methods
38
39        /// <summary>
40        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"/> event.
41        /// </summary>
42        /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
43        protected override void OnPreRender(EventArgs e)
44        {
45            base.OnPreRender(e);
46
47            if (this.Page.IsPostBack)
48            {
49                return;
50            }
51        
52            var settings = this.GetSettings();
53            this.txtNumberOfPosts.Text = settings.ContainsKey("numberofposts") ? settings["numberofposts"] : "10";
54
55            this.cbShowComments.Checked = !settings.ContainsKey("showcomments") ||
56                                          settings["showcomments"].Equals("true", StringComparison.OrdinalIgnoreCase);
57
58            this.cbShowRating.Checked = !settings.ContainsKey("showrating") || settings["showrating"].Equals("true", StringComparison.OrdinalIgnoreCase);
59        }
60
61        #endregion
62    }
63}