11using BlogEngine . Core . Data . Contracts ;
22using BlogEngine . Core . Data . Models ;
3+ using BlogEngine . Core . Data . Services ;
34using System ;
45using System . Collections . Generic ;
56using System . Globalization ;
@@ -23,8 +24,8 @@ public class PageRepository : IPageRepository
2324 /// <returns></returns>
2425 public IEnumerable < PageItem > Find ( int take = 10 , int skip = 0 , string filter = "" , string order = "" )
2526 {
26- if ( ! Security . IsAuthorizedTo ( BlogEngine . Core . Rights . ViewPublicPages ) )
27- throw new System . UnauthorizedAccessException ( ) ;
27+ if ( ! Security . IsAuthorizedTo ( Rights . ViewPublicPages ) )
28+ throw new UnauthorizedAccessException ( ) ;
2829
2930 if ( string . IsNullOrEmpty ( filter ) ) filter = "1==1" ;
3031 if ( string . IsNullOrEmpty ( order ) ) order = "DateCreated desc" ;
@@ -36,7 +37,7 @@ public IEnumerable<PageItem> Find(int take = 10, int skip = 0, string filter = "
3637 if ( take == 0 ) take = Page . Pages . Count ;
3738
3839 foreach ( var item in query . OrderBy ( order ) . Skip ( skip ) . Take ( take ) )
39- items . Add ( ToJson ( ( BlogEngine . Core . Page ) item ) ) ;
40+ items . Add ( Json . GetPage ( item ) ) ;
4041
4142 return items ;
4243 }
@@ -48,11 +49,11 @@ public IEnumerable<PageItem> Find(int take = 10, int skip = 0, string filter = "
4849 /// <returns>Page object</returns>
4950 public PageDetail FindById ( Guid id )
5051 {
51- if ( ! Security . IsAuthorizedTo ( BlogEngine . Core . Rights . ViewPublicPages ) )
52- throw new System . UnauthorizedAccessException ( ) ;
52+ if ( ! Security . IsAuthorizedTo ( Rights . ViewPublicPages ) )
53+ throw new UnauthorizedAccessException ( ) ;
5354 try
5455 {
55- return ToJsonDetail ( ( from p in Page . Pages . ToList ( ) where p . Id == id select p ) . FirstOrDefault ( ) ) ;
56+ return Json . GetPageDetail ( ( from p in Page . Pages . ToList ( ) where p . Id == id select p ) . FirstOrDefault ( ) ) ;
5657 }
5758 catch ( Exception )
5859 {
@@ -67,12 +68,12 @@ public PageDetail FindById(Guid id)
6768 /// <returns>Saved page with new ID</returns>
6869 public PageDetail Add ( PageDetail detail )
6970 {
70- if ( ! Security . IsAuthorizedTo ( BlogEngine . Core . Rights . CreateNewPages ) )
71- throw new System . UnauthorizedAccessException ( ) ;
71+ if ( ! Security . IsAuthorizedTo ( Rights . CreateNewPages ) )
72+ throw new UnauthorizedAccessException ( ) ;
7273
7374 var page = new Page ( ) ;
7475 if ( Save ( page , detail ) )
75- return ToJsonDetail ( page ) ;
76+ return Json . GetPageDetail ( page ) ;
7677
7778 return null ;
7879 }
@@ -85,8 +86,8 @@ public PageDetail Add(PageDetail detail)
8586 /// <returns>True on success</returns>
8687 public bool Update ( PageDetail page , string action )
8788 {
88- if ( ! Security . IsAuthorizedTo ( BlogEngine . Core . Rights . CreateNewPages ) )
89- throw new System . UnauthorizedAccessException ( ) ;
89+ if ( ! Security . IsAuthorizedTo ( Rights . CreateNewPages ) )
90+ throw new UnauthorizedAccessException ( ) ;
9091
9192 var corePage = ( from p in Page . Pages . ToList ( ) where p . Id == page . Id select p ) . FirstOrDefault ( ) ;
9293
@@ -116,8 +117,8 @@ public bool Update(PageDetail page, string action)
116117 /// <returns>True on success</returns>
117118 public bool Remove ( Guid id )
118119 {
119- if ( ! Security . IsAuthorizedTo ( BlogEngine . Core . Rights . CreateNewPages ) )
120- throw new System . UnauthorizedAccessException ( ) ;
120+ if ( ! Security . IsAuthorizedTo ( Rights . CreateNewPages ) )
121+ throw new UnauthorizedAccessException ( ) ;
121122
122123 var page = ( from p in Page . Pages . ToList ( ) where p . Id == id select p ) . FirstOrDefault ( ) ;
123124
@@ -171,62 +172,6 @@ static bool Save(Page page, PageDetail detail)
171172 return true ;
172173 }
173174
174- static PageItem ToJson ( Page page )
175- {
176- Page parent = null ;
177- SelectOption parentOption = null ;
178-
179- if ( page . Parent != Guid . Empty )
180- {
181- parent = Page . Pages . FirstOrDefault ( p => p . Id . Equals ( page . Parent ) ) ;
182- parentOption = new SelectOption { IsSelected = false , OptionName = parent . Title , OptionValue = parent . Id . ToString ( ) } ;
183- }
184- return new PageItem
185- {
186- Id = page . Id ,
187- ShowInList = page . ShowInList ,
188- Title = page . Title ,
189- Slug = page . Slug ,
190- Parent = parentOption ,
191- Keywords = page . Keywords ,
192- DateCreated = page . DateCreated . ToString ( "yyyy-MM-dd HH:mm" ) ,
193- HasChildren = page . HasChildPages ,
194- IsPublished = page . IsPublished ,
195- IsFrontPage = page . IsFrontPage ,
196- SortOrder = page . SortOrder ,
197- } ;
198- }
199-
200- static PageDetail ToJsonDetail ( Page page )
201- {
202- Page parent = null ;
203- SelectOption parentOption = null ;
204-
205- if ( page . Parent != Guid . Empty )
206- {
207- parent = Page . Pages . FirstOrDefault ( p => p . Id . Equals ( page . Parent ) ) ;
208- parentOption = new SelectOption { IsSelected = false , OptionName = parent . Title , OptionValue = parent . Id . ToString ( ) } ;
209- }
210- return new PageDetail
211- {
212- Id = page . Id ,
213- ShowInList = page . ShowInList ,
214- Title = page . Title ,
215- Slug = page . Slug ,
216- RelativeLink = page . RelativeLink ,
217- Content = page . Content ,
218- Parent = parentOption ,
219- Description = page . Description ,
220- Keywords = page . Keywords ,
221- DateCreated = page . DateCreated . ToString ( "yyyy-MM-dd HH:mm" ) ,
222- HasChildren = page . HasChildPages ,
223- IsPublished = page . IsPublished ,
224- IsFrontPage = page . IsFrontPage ,
225- IsDeleted = page . IsDeleted ,
226- SortOrder = page . SortOrder ,
227- } ;
228- }
229-
230175 static string GetUniqueSlug ( string slug )
231176 {
232177 string s = Utils . RemoveIllegalCharacters ( slug . Trim ( ) ) ;
0 commit comments