refactoring

This commit is contained in:
Paul Schneider 2015-10-17 19:07:54 +02:00
commit bb5e34a61d
29 changed files with 609 additions and 272 deletions

View file

@ -18,15 +18,17 @@ namespace Yavsc.Model.Blogs
public BlogEntryCollection ()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.Blogs.BlogEntryCollection"/> class.
/// </summary>
/// <param name="items">Items.</param>
public BlogEntryCollection(IEnumerable<BlogEntry> items)
public BlogEntryCollection (IEnumerable<BlogEntry> items)
{
if (items!=null)
if (items != null)
this.AddRange (items);
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current <see cref="Yavsc.Model.Blogs.BlogEntryCollection"/>.
/// </summary>
@ -57,115 +59,81 @@ namespace Yavsc.Model.Blogs
{
return this.Where (x => x.Title == title).ToArray ();
}
/// <summary>
/// Filters the current collection for a given user by its name.
/// Assumes that this user is not an author of any of these posts.
/// </summary>
/// <param name="username">Username.</param>
public BlogEntryCollection FilterFor(string username)
public BlogEntryCollection FilterFor (string username)
{
BlogEntryCollection res = new BlogEntryCollection ();
foreach (BlogEntry be in this) {
if (be.Visible &&
(be.AllowedCircles == null ||
(username!= null && CircleManager.DefaultProvider.Matches
(be.AllowedCircles,username))))
{
res.Add(be);
}
if (be.Visible &&
(be.AllowedCircles == null ||
(username != null && CircleManager.DefaultProvider.Matches
(be.AllowedCircles, username)))) {
res.Add (be);
}
}
return res;
}
/// <summary>
/// Base post info.
/// </summary>
public class BasePostInfo: BasePost {
/// <summary>
/// The intro.
/// </summary>
public string Intro;
}
/// <summary>
/// Post info.
/// </summary>
public class PostInfoByTitle : BasePostInfo {
/// <summary>
/// The name of the user.
/// </summary>
public string Author;
}
/// <summary>
/// Post info by user.
/// </summary>
public class PostInfoByUser : BasePostInfo {
/// <summary>
/// The name of the user.
/// </summary>
public string Title;
}
/// <summary>
/// Groups by title.
/// </summary>
public IEnumerable<IGrouping<string,PostInfoByTitle>> GroupByTitle()
public IEnumerable<IGrouping<string,PostInfoByTitle>> GroupByTitle ()
{
bool truncated;
return from be in this
orderby be.Posted descending
group
new PostInfoByTitle { Author=be.Author, Id=be.Id,
Posted=be.Posted, Modified=be.Modified,
Intro = MarkdownHelper.MarkdownIntro(be.Content, out truncated),
group
new PostInfoByTitle { Author = be.Author, Id = be.Id,
Posted = be.Posted, Modified = be.Modified,
Intro = MarkdownHelper.MarkdownIntro (be.Content, out truncated),
Visible = be.Visible,
Photo = be.Photo
}
by be.Title
into titlegroup
select titlegroup;
select titlegroup;
}
/// <summary>
/// Groups by user.
/// </summary>
/// <returns>The by user.</returns>
public IEnumerable<IGrouping<string,PostInfoByUser>> GroupByUser()
public IEnumerable<IGrouping<string,PostInfoByUser>> GroupByUser ()
{
bool truncated;
return from be in this
orderby be.Posted descending
group
new PostInfoByUser {
Title=be.Title,
Id=be.Id,
Posted=be.Posted,
Modified=be.Modified,
Intro = MarkdownHelper.MarkdownIntro(be.Content, out truncated) ,
group
new PostInfoByUser {
Title = be.Title,
Id = be.Id,
Posted = be.Posted,
Modified = be.Modified,
Intro = MarkdownHelper.MarkdownIntro (be.Content, out truncated),
Photo = be.Photo,
Visible = be.Visible
}
by be.Author
into usergroup
select usergroup;
select usergroup;
}
/// <summary>
/// Gets the titles.
/// </summary>
/// <value>The titles.</value>
public string[] Titles { get {
public string[] Titles {
get {
string[] result = this.Select (x => x.Title).Distinct ().ToArray ();
if (result == null)
return new string[0];
return result;
} }
}
}
}
}