using System;
using System.Configuration;
using System.Collections.Generic;
using Yavsc.Model.Blogs;
using System.Linq;
namespace Yavsc.Model.Blogs
{
///
/// Blog entry collection.
///
public class BlogEntryCollection : List
{
///
/// Initializes a new instance of the class.
///
public BlogEntryCollection ()
{
}
///
/// Initializes a new instance of the class.
///
/// Items.
public BlogEntryCollection(IEnumerable items)
{
if (items!=null)
this.AddRange (items);
}
///
/// Returns a that represents the current .
///
/// A that represents the current .
public override string ToString ()
{
string titles = Titles == null ?
"none" : string.Join (", ", Titles);
return string.Format ("[BlogEntryCollection: Titles={0}]", titles);
}
///
/// Get the specified bid.
///
/// Bid.
public BlogEntry Get (long bid)
{
return this.First (x => x.Id == bid);
}
///
/// Filters this collection on
/// the given title.
///
/// The by title.
/// Title.
public BlogEntry [] FilterOnTitle (string title)
{
return this.Where (x => x.Title == title).ToArray ();
}
///
/// Base post info.
///
public class BasePostInfo {
///
/// The identifier.
///
public long Id;
///
/// The posted.
///
public DateTime Posted;
///
/// The modified.
///
public DateTime Modified;
///
/// The intro.
///
public string Intro;
}
///
/// Post info.
///
public class PostInfoByTitle : BasePostInfo {
///
/// The name of the user.
///
public string Author;
}
///
/// Post info by user.
///
public class PostInfoByUser : BasePostInfo {
///
/// The name of the user.
///
public string Title;
}
///
/// Groups by title.
///
public IEnumerable> 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) }
by be.Title
into titlegroup
select titlegroup;
}
///
/// Groups by user.
///
/// The by user.
public IEnumerable> 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) }
by be.Author
into usergroup
select usergroup;
}
///
/// Gets the titles.
///
/// The titles.
public string[] Titles { get {
string[] result = this.Select (x => x.Title).Distinct ().ToArray ();
if (result == null)
return new string[0];
return result;
} }
}
}