Skip to content

Commit f86d672

Browse files
committed
Added settings view model and time zone id.
1 parent 5fbbe20 commit f86d672

11 files changed

Lines changed: 231 additions & 179 deletions

File tree

BlogEngine/BlogEngine.Core/BlogEngine.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
<Reference Include="System.Xml" />
120120
</ItemGroup>
121121
<ItemGroup>
122+
<Compile Include="Data\ViewModels\SettingsVM.cs" />
122123
<Compile Include="Services\Syndication\BlogML\BaseReader.cs" />
123124
<Compile Include="Services\Syndication\BlogML\BlogImporter.cs" />
124125
<Compile Include="Services\Syndication\BlogML\BlogMLExtendedPost.cs" />

BlogEngine/BlogEngine.Core/BlogSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,10 @@ public enum CommentsBy
10831083
/// </summary>
10841084
/// <value>The maximum number of characters to display.</value>
10851085
public double Timezone { get; set; }
1086+
/// <summary>
1087+
/// Time zone id
1088+
/// </summary>
1089+
public string TimeZoneId { get; set; }
10861090

10871091
/// <summary>
10881092
/// Converts time passed from client into UTC server time

BlogEngine/BlogEngine.Core/Data/Contracts/ISettingsRepository.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BlogEngine.Core.Data.Models;
2+
using BlogEngine.Core.Data.ViewModels;
23

34
namespace BlogEngine.Core.Data.Contracts
45
{
@@ -10,8 +11,8 @@ public interface ISettingsRepository
1011
/// <summary>
1112
/// Get all settings
1213
/// </summary>
13-
/// <returns>List of settings</returns>
14-
Settings Get();
14+
/// <returns>Settings view model</returns>
15+
SettingsVM Get();
1516
/// <summary>
1617
/// Update settings
1718
/// </summary>

BlogEngine/BlogEngine.Core/Data/Models/Settings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public Settings() { }
7171
/// </summary>
7272
public double Timezone { get; set; }
7373
/// <summary>
74+
/// Time zone id
75+
/// </summary>
76+
public string TimeZoneId { get; set; }
77+
/// <summary>
7478
/// Removes extensions from urls
7579
/// </summary>
7680
public bool RemoveExtensionsFromUrls { get; set; }
Lines changed: 125 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BlogEngine.Core.Data.Models;
2+
using BlogEngine.Core.Data.ViewModels;
23
using BlogEngine.Core.Data.Contracts;
34

45
namespace BlogEngine.Core.Data
@@ -12,122 +13,13 @@ public class SettingsRepository : ISettingsRepository
1213
/// Get all settings
1314
/// </summary>
1415
/// <returns>Settings object</returns>
15-
public Settings Get()
16+
public SettingsVM Get()
1617
{
17-
if (!Security.IsAuthorizedTo(Rights.AccessAdminSettingsPages))
18-
throw new System.UnauthorizedAccessException();
19-
20-
var ns = new Settings();
21-
var bs = BlogSettings.Instance;
22-
23-
// basic
24-
ns.Name = bs.Name;
25-
ns.Description = bs.Description;
26-
ns.PostsPerPage = bs.PostsPerPage;
27-
ns.ThemeCookieName = bs.ThemeCookieName;
28-
ns.UseBlogNameInPageTitles = bs.UseBlogNameInPageTitles;
29-
ns.EnableRelatedPosts = bs.EnableRelatedPosts;
30-
ns.EnableRating = bs.EnableRating;
31-
ns.ShowDescriptionInPostList = bs.ShowDescriptionInPostList;
32-
ns.DescriptionCharacters = bs.DescriptionCharacters;
33-
ns.ShowDescriptionInPostListForPostsByTagOrCategory = bs.ShowDescriptionInPostListForPostsByTagOrCategory;
34-
ns.DescriptionCharactersForPostsByTagOrCategory = bs.DescriptionCharactersForPostsByTagOrCategory;
35-
ns.TimeStampPostLinks = bs.TimeStampPostLinks;
36-
ns.ShowPostNavigation = bs.ShowPostNavigation;
37-
ns.Culture = bs.Culture;
38-
ns.Timezone = bs.Timezone;
39-
ns.RemoveExtensionsFromUrls = bs.RemoveExtensionsFromUrls;
40-
ns.RedirectToRemoveFileExtension = bs.RedirectToRemoveFileExtension;
41-
ns.DesktopTheme = bs.Theme;
42-
43-
// advanced
44-
ns.HandleWwwSubdomain = bs.HandleWwwSubdomain;
45-
ns.EnableHttpCompression = bs.EnableHttpCompression;
46-
ns.CompressWebResource = bs.CompressWebResource;
47-
ns.EnableOpenSearch = bs.EnableOpenSearch;
48-
ns.RequireSslForMetaWeblogApi = bs.RequireSslMetaWeblogApi;
49-
50-
ns.EnablePasswordReset = bs.EnablePasswordReset;
51-
ns.EnableSelfRegistration = bs.EnableSelfRegistration;
52-
ns.CreateBlogOnSelfRegistration = bs.CreateBlogOnSelfRegistration;
53-
ns.AllowServerToDownloadRemoteFiles = bs.AllowServerToDownloadRemoteFiles;
54-
ns.RemoteFileDownloadTimeout = bs.RemoteFileDownloadTimeout;
55-
ns.RemoteMaxFileSize = bs.RemoteMaxFileSize;
56-
ns.SelfRegistrationInitialRole = bs.SelfRegistrationInitialRole;
57-
if (string.IsNullOrEmpty(ns.SelfRegistrationInitialRole))
58-
{
59-
// set to default editor role if not set in settings
60-
ns.SelfRegistrationInitialRole = BlogConfig.EditorsRole;
61-
}
62-
63-
// feed
64-
ns.AuthorName = bs.AuthorName;
65-
ns.FeedAuthor = bs.FeedAuthor;
66-
ns.Endorsement = bs.Endorsement;
67-
ns.AlternateFeedUrl = bs.AlternateFeedUrl;
68-
ns.Language = bs.Language;
69-
ns.PostsPerFeed = bs.PostsPerFeed;
70-
ns.EnableEnclosures = bs.EnableEnclosures;
71-
ns.SyndicationFormat = bs.SyndicationFormat;
72-
ns.EnableTagExport = bs.EnableTagExport;
73-
74-
// email
75-
ns.Email = bs.Email;
76-
ns.SmtpServer = bs.SmtpServer;
77-
ns.SmtpServerPort = bs.SmtpServerPort;
78-
ns.SmtpUserName = bs.SmtpUserName;
79-
ns.SmtpPassword = bs.SmtpPassword;
80-
ns.EmailSubjectPrefix = bs.EmailSubjectPrefix;
81-
ns.EnableSsl = bs.EnableSsl;
82-
ns.SendMailOnComment = bs.SendMailOnComment;
18+
var vm = new SettingsVM();
8319

84-
// controls
85-
ns.SearchButtonText = bs.SearchButtonText;
86-
ns.SearchCommentLabelText = bs.SearchCommentLabelText;
87-
ns.SearchDefaultText = bs.SearchDefaultText;
88-
ns.EnableCommentSearch = bs.EnableCommentSearch;
89-
ns.ShowIncludeCommentsOption = bs.ShowIncludeCommentsOption;
90-
ns.ContactFormMessage = bs.ContactFormMessage;
91-
ns.ContactThankMessage = bs.ContactThankMessage;
92-
ns.ContactErrorMessage = bs.ContactErrorMessage;
93-
ns.EnableContactAttachments = bs.EnableContactAttachments;
94-
ns.EnableRecaptchaOnContactForm = bs.EnableRecaptchaOnContactForm;
95-
ns.ErrorTitle = bs.ErrorTitle;
96-
ns.ErrorText = bs.ErrorText;
97-
98-
// custom code
99-
ns.HtmlHeader = bs.HtmlHeader;
100-
ns.TrackingScript = bs.TrackingScript;
20+
vm.Settings = GetSettings();
10121

102-
// comments
103-
ns.DaysCommentsAreEnabled = bs.DaysCommentsAreEnabled;
104-
ns.IsCommentsEnabled = bs.IsCommentsEnabled;
105-
ns.EnableCommentsModeration = bs.EnableCommentsModeration;
106-
ns.IsCommentNestingEnabled = bs.IsCommentNestingEnabled;
107-
ns.Avatar = bs.Avatar;
108-
ns.EnablePingBackSend = bs.EnablePingBackSend;
109-
ns.EnablePingBackReceive = bs.EnablePingBackReceive;
110-
ns.EnableTrackBackSend = bs.EnableTrackBackSend;
111-
ns.EnableTrackBackReceive = bs.EnableTrackBackReceive;
112-
ns.CommentsPerPage = bs.CommentsPerPage;
113-
ns.EnableCountryInComments = bs.EnableCountryInComments;
114-
ns.EnableWebsiteInComments = bs.EnableWebsiteInComments;
115-
ns.ShowLivePreview = bs.ShowLivePreview;
116-
117-
ns.CommentProvider = bs.CommentProvider;
118-
ns.DisqusDevMode = bs.DisqusDevMode;
119-
ns.DisqusAddCommentsToPages = bs.DisqusAddCommentsToPages;
120-
ns.DisqusWebsiteName = bs.DisqusWebsiteName;
121-
122-
// custom filters
123-
ns.CommentWhiteListCount = bs.CommentWhiteListCount;
124-
ns.CommentBlackListCount = bs.CommentBlackListCount;
125-
ns.AddIpToWhitelistFilterOnApproval = bs.AddIpToWhitelistFilterOnApproval;
126-
ns.TrustAuthenticatedUsers = bs.TrustAuthenticatedUsers;
127-
ns.BlockAuthorOnCommentDelete = bs.BlockAuthorOnCommentDelete;
128-
ns.AddIpToBlacklistFilterOnRejection = bs.AddIpToBlacklistFilterOnRejection;
129-
130-
return ns;
22+
return vm;
13123
}
13224

13325
/// <summary>
@@ -157,6 +49,7 @@ public bool Update(Settings ns)
15749
bs.ShowPostNavigation = ns.ShowPostNavigation;
15850
bs.Culture = ns.Culture;
15951
bs.Timezone = ns.Timezone;
52+
bs.TimeZoneId = ns.TimeZoneId;
16053
bs.RemoveExtensionsFromUrls = ns.RemoveExtensionsFromUrls;
16154
bs.RedirectToRemoveFileExtension = ns.RedirectToRemoveFileExtension;
16255
bs.Theme = ns.DesktopTheme;
@@ -246,5 +139,124 @@ public bool Update(Settings ns)
246139
bs.Save();
247140
return true;
248141
}
142+
143+
private Settings GetSettings()
144+
{
145+
if (!Security.IsAuthorizedTo(Rights.AccessAdminSettingsPages))
146+
throw new System.UnauthorizedAccessException();
147+
148+
var ns = new Settings();
149+
var bs = BlogSettings.Instance;
150+
151+
// basic
152+
ns.Name = bs.Name;
153+
ns.Description = bs.Description;
154+
ns.PostsPerPage = bs.PostsPerPage;
155+
ns.ThemeCookieName = bs.ThemeCookieName;
156+
ns.UseBlogNameInPageTitles = bs.UseBlogNameInPageTitles;
157+
ns.EnableRelatedPosts = bs.EnableRelatedPosts;
158+
ns.EnableRating = bs.EnableRating;
159+
ns.ShowDescriptionInPostList = bs.ShowDescriptionInPostList;
160+
ns.DescriptionCharacters = bs.DescriptionCharacters;
161+
ns.ShowDescriptionInPostListForPostsByTagOrCategory = bs.ShowDescriptionInPostListForPostsByTagOrCategory;
162+
ns.DescriptionCharactersForPostsByTagOrCategory = bs.DescriptionCharactersForPostsByTagOrCategory;
163+
ns.TimeStampPostLinks = bs.TimeStampPostLinks;
164+
ns.ShowPostNavigation = bs.ShowPostNavigation;
165+
ns.Culture = bs.Culture;
166+
ns.Timezone = bs.Timezone;
167+
ns.TimeZoneId = bs.TimeZoneId == null ? "UTC" : bs.TimeZoneId;
168+
ns.RemoveExtensionsFromUrls = bs.RemoveExtensionsFromUrls;
169+
ns.RedirectToRemoveFileExtension = bs.RedirectToRemoveFileExtension;
170+
ns.DesktopTheme = bs.Theme;
171+
172+
// advanced
173+
ns.HandleWwwSubdomain = bs.HandleWwwSubdomain;
174+
ns.EnableHttpCompression = bs.EnableHttpCompression;
175+
ns.CompressWebResource = bs.CompressWebResource;
176+
ns.EnableOpenSearch = bs.EnableOpenSearch;
177+
ns.RequireSslForMetaWeblogApi = bs.RequireSslMetaWeblogApi;
178+
179+
ns.EnablePasswordReset = bs.EnablePasswordReset;
180+
ns.EnableSelfRegistration = bs.EnableSelfRegistration;
181+
ns.CreateBlogOnSelfRegistration = bs.CreateBlogOnSelfRegistration;
182+
ns.AllowServerToDownloadRemoteFiles = bs.AllowServerToDownloadRemoteFiles;
183+
ns.RemoteFileDownloadTimeout = bs.RemoteFileDownloadTimeout;
184+
ns.RemoteMaxFileSize = bs.RemoteMaxFileSize;
185+
ns.SelfRegistrationInitialRole = bs.SelfRegistrationInitialRole;
186+
if (string.IsNullOrEmpty(ns.SelfRegistrationInitialRole))
187+
{
188+
// set to default editor role if not set in settings
189+
ns.SelfRegistrationInitialRole = BlogConfig.EditorsRole;
190+
}
191+
192+
// feed
193+
ns.AuthorName = bs.AuthorName;
194+
ns.FeedAuthor = bs.FeedAuthor;
195+
ns.Endorsement = bs.Endorsement;
196+
ns.AlternateFeedUrl = bs.AlternateFeedUrl;
197+
ns.Language = bs.Language;
198+
ns.PostsPerFeed = bs.PostsPerFeed;
199+
ns.EnableEnclosures = bs.EnableEnclosures;
200+
ns.SyndicationFormat = bs.SyndicationFormat;
201+
ns.EnableTagExport = bs.EnableTagExport;
202+
203+
// email
204+
ns.Email = bs.Email;
205+
ns.SmtpServer = bs.SmtpServer;
206+
ns.SmtpServerPort = bs.SmtpServerPort;
207+
ns.SmtpUserName = bs.SmtpUserName;
208+
ns.SmtpPassword = bs.SmtpPassword;
209+
ns.EmailSubjectPrefix = bs.EmailSubjectPrefix;
210+
ns.EnableSsl = bs.EnableSsl;
211+
ns.SendMailOnComment = bs.SendMailOnComment;
212+
213+
// controls
214+
ns.SearchButtonText = bs.SearchButtonText;
215+
ns.SearchCommentLabelText = bs.SearchCommentLabelText;
216+
ns.SearchDefaultText = bs.SearchDefaultText;
217+
ns.EnableCommentSearch = bs.EnableCommentSearch;
218+
ns.ShowIncludeCommentsOption = bs.ShowIncludeCommentsOption;
219+
ns.ContactFormMessage = bs.ContactFormMessage;
220+
ns.ContactThankMessage = bs.ContactThankMessage;
221+
ns.ContactErrorMessage = bs.ContactErrorMessage;
222+
ns.EnableContactAttachments = bs.EnableContactAttachments;
223+
ns.EnableRecaptchaOnContactForm = bs.EnableRecaptchaOnContactForm;
224+
ns.ErrorTitle = bs.ErrorTitle;
225+
ns.ErrorText = bs.ErrorText;
226+
227+
// custom code
228+
ns.HtmlHeader = bs.HtmlHeader;
229+
ns.TrackingScript = bs.TrackingScript;
230+
231+
// comments
232+
ns.DaysCommentsAreEnabled = bs.DaysCommentsAreEnabled;
233+
ns.IsCommentsEnabled = bs.IsCommentsEnabled;
234+
ns.EnableCommentsModeration = bs.EnableCommentsModeration;
235+
ns.IsCommentNestingEnabled = bs.IsCommentNestingEnabled;
236+
ns.Avatar = bs.Avatar;
237+
ns.EnablePingBackSend = bs.EnablePingBackSend;
238+
ns.EnablePingBackReceive = bs.EnablePingBackReceive;
239+
ns.EnableTrackBackSend = bs.EnableTrackBackSend;
240+
ns.EnableTrackBackReceive = bs.EnableTrackBackReceive;
241+
ns.CommentsPerPage = bs.CommentsPerPage;
242+
ns.EnableCountryInComments = bs.EnableCountryInComments;
243+
ns.EnableWebsiteInComments = bs.EnableWebsiteInComments;
244+
ns.ShowLivePreview = bs.ShowLivePreview;
245+
246+
ns.CommentProvider = bs.CommentProvider;
247+
ns.DisqusDevMode = bs.DisqusDevMode;
248+
ns.DisqusAddCommentsToPages = bs.DisqusAddCommentsToPages;
249+
ns.DisqusWebsiteName = bs.DisqusWebsiteName;
250+
251+
// custom filters
252+
ns.CommentWhiteListCount = bs.CommentWhiteListCount;
253+
ns.CommentBlackListCount = bs.CommentBlackListCount;
254+
ns.AddIpToWhitelistFilterOnApproval = bs.AddIpToWhitelistFilterOnApproval;
255+
ns.TrustAuthenticatedUsers = bs.TrustAuthenticatedUsers;
256+
ns.BlockAuthorOnCommentDelete = bs.BlockAuthorOnCommentDelete;
257+
ns.AddIpToBlacklistFilterOnRejection = bs.AddIpToBlacklistFilterOnRejection;
258+
259+
return ns;
260+
}
249261
}
250262
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using BlogEngine.Core.Data.Models;
4+
5+
namespace BlogEngine.Core.Data.ViewModels
6+
{
7+
/// <summary>
8+
/// Setting view model
9+
/// </summary>
10+
public class SettingsVM
11+
{
12+
/// <summary>
13+
/// Blog settings
14+
/// </summary>
15+
public Settings Settings { get; set; }
16+
17+
/// <summary>
18+
/// Time zones
19+
/// </summary>
20+
public List<SelectOption> TimeZones
21+
{
22+
get
23+
{
24+
var zones = new List<SelectOption>();
25+
foreach (var zone in TimeZoneInfo.GetSystemTimeZones())
26+
{
27+
zones.Add(new SelectOption { OptionName = zone.DisplayName, OptionValue = zone.Id });
28+
}
29+
return zones;
30+
}
31+
}
32+
/// <summary>
33+
/// Feed options
34+
/// </summary>
35+
public List<SelectOption> FeedOptions
36+
{
37+
get
38+
{
39+
var options = new List<SelectOption>();
40+
options.Add(new SelectOption { OptionName = "RSS 2.0", OptionValue = "Rss" });
41+
options.Add(new SelectOption { OptionName = "Atom 1.0", OptionValue = "Atom" });
42+
return options;
43+
}
44+
}
45+
/// <summary>
46+
/// Closed days options
47+
/// </summary>
48+
public List<SelectOption> CloseDaysOptions
49+
{
50+
get
51+
{
52+
var options = new List<SelectOption>();
53+
options.Add(new SelectOption { OptionName = "Never" , OptionValue = "0" });
54+
options.Add(new SelectOption { OptionName = "1", OptionValue = "1" });
55+
options.Add(new SelectOption { OptionName = "2", OptionValue = "2" });
56+
options.Add(new SelectOption { OptionName = "3", OptionValue = "3" });
57+
options.Add(new SelectOption { OptionName = "7", OptionValue = "7" });
58+
options.Add(new SelectOption { OptionName = "10", OptionValue = "10" });
59+
options.Add(new SelectOption { OptionName = "14", OptionValue = "14" });
60+
options.Add(new SelectOption { OptionName = "21", OptionValue = "21" });
61+
options.Add(new SelectOption { OptionName = "30", OptionValue = "30" });
62+
options.Add(new SelectOption { OptionName = "60", OptionValue = "60" });
63+
options.Add(new SelectOption { OptionName = "90", OptionValue = "90" });
64+
options.Add(new SelectOption { OptionName = "180", OptionValue = "180" });
65+
options.Add(new SelectOption { OptionName = "365", OptionValue = "365" });
66+
return options;
67+
}
68+
}
69+
70+
//public List<SelectOption> FeedOptions
71+
//{
72+
// get
73+
// {
74+
// var options = new List<SelectOption>();
75+
// options.Add(new SelectOption { OptionName = "", OptionValue = "" });
76+
// return options;
77+
// }
78+
//}
79+
80+
}
81+
}

0 commit comments

Comments
 (0)