using System;
using Yavsc.Model.Blogs;
using Yavsc.Model.RolesAndMembers;
using System.Web;
using System.Web.Security;
namespace Yavsc.Model.Blogs
{
///
/// Blog manager.
///
public static class BlogManager
{
///
/// Removes the comment.
///
/// The comment.
/// Cmtid.
public static long RemoveComment(long cmtid)
{
return Provider.RemoveComment (cmtid);
}
///
/// Comment the specified from, postid, content and visible.
///
/// From.
/// Postid.
/// Content.
/// If set to true visible.
public static void Comment (string from, long postid, string content, bool visible)
{
provider.Comment (from, postid, content);
}
static BlogProvider provider;
///
/// Gets the provider.
///
/// The provider.
public static BlogProvider Provider {
get {
if (provider == null)
provider = BlogHelper.GetProvider();
return provider;
}
}
///
/// Gets the post.
///
/// The post.
/// Username.
/// Title.
public static BlogEntry GetPost (string username, string title)
{
return Provider.GetPost (username, title );
}
///
/// Gets the post.
///
/// The post.
/// Postid.
public static BlogEntry GetPost(long postid)
{
return Provider.GetPost (postid);
}
///
/// Post the specified username, title, content and visible.
///
/// Username.
/// Title.
/// Content.
/// If set to true visible.
public static void Post(string username, string title, string content, bool visible)
{
Provider.Post(username, title, content, visible );
}
///
/// Updates the post.
///
/// Postid.
/// Title.
/// Content.
/// If set to true visible.
public static void UpdatePost(long postid, string title, string content, bool visible)
{
Provider.UpdatePost(postid, title, content, visible);
}
///
/// Finds the post.
///
/// The post.
/// Pattern.
/// Searchflags.
/// Page index.
/// Page size.
/// Total records.
public static BlogEntryCollection FindPost (string pattern, FindBlogEntryFlags searchflags, int pageIndex, int pageSize, out int totalRecords)
{
return Provider.FindPost (pattern, searchflags, pageIndex, pageSize, out totalRecords);
}
///
/// Removes the post.
///
/// Username.
/// Title.
public static void RemovePost (string username, string title)
{
if (!Roles.IsUserInRole ("Admin")) {
string rguser = Membership.GetUser ().UserName;
if (rguser != username) {
throw new AccessViolationException (
string.Format (
"{1}, Vous n'avez pas le droit de suprimer des billets du Blog de {0}",
username,rguser));
}
}
Provider.RemovePost (username, title);
}
///
/// Lasts the posts.
///
/// The posts.
/// Page index.
/// Page size.
/// Total records.
public static BlogEntryCollection LastPosts (int pageIndex, int pageSize, out int totalRecords)
{
return Provider.LastPosts (pageIndex, pageSize, out totalRecords);
}
///
/// Gets the comments.
///
/// The comments.
/// Postid.
/// If set to true get hidden.
public static Comment[] GetComments(long postid, bool getHidden=true)
{
return Provider.GetComments (postid,getHidden);
}
///
/// Tag the specified post by postid.
///
/// Postid.
/// Tag.
/// The tag identifier
public static long Tag(long postid, string tag) {
return Provider.Tag (postid, tag);
}
}
}