|
|
|
|
@ -33,8 +33,8 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "INSERT INTO tagged (tagid,postid) VALUES (:tid,:pid)";
|
|
|
|
|
cmd.Parameters.AddWithValue("tid",tid);
|
|
|
|
|
cmd.Parameters.AddWithValue("pid",postid);
|
|
|
|
|
cmd.Parameters.AddWithValue ("tid", tid);
|
|
|
|
|
cmd.Parameters.AddWithValue ("pid", postid);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
cmd.ExecuteNonQuery ();
|
|
|
|
|
return tid;
|
|
|
|
|
@ -47,8 +47,9 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
/// <param name="postid">Postid.</param>
|
|
|
|
|
/// <param name="tagid">Tagid.</param>
|
|
|
|
|
/// <param name="name">Name.</param>
|
|
|
|
|
override public void Untag(long postid, string name) {
|
|
|
|
|
Untag(postid, GetTagId (name));
|
|
|
|
|
override public void Untag (long postid, string name)
|
|
|
|
|
{
|
|
|
|
|
Untag (postid, GetTagId (name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
@ -57,7 +58,8 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
/// <param name="postid">Postid.</param>
|
|
|
|
|
/// <param name="tagid">Tagid.</param>
|
|
|
|
|
/// <param name="tid">Tid.</param>
|
|
|
|
|
override public void Untag(long postid, long tid) {
|
|
|
|
|
override public void Untag (long postid, long tid)
|
|
|
|
|
{
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "DELETE FROM tagged WHERE postid = :pid AND tagid = :tid";
|
|
|
|
|
@ -67,6 +69,7 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
cmd.ExecuteNonQuery ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the comments.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -77,32 +80,33 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
{
|
|
|
|
|
List<Comment> cmts = new List<Comment> ();
|
|
|
|
|
|
|
|
|
|
using (NpgsqlConnection cnx=new NpgsqlConnection(connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
|
|
|
|
|
cmd.CommandText = "select _id, username, bcontent, modified, posted, visible from comment " +
|
|
|
|
|
"where applicationname = :appname and postid = :id" +
|
|
|
|
|
((getHidden) ? " and visible = true ":" ") +
|
|
|
|
|
"order by posted asc" ;
|
|
|
|
|
((getHidden) ? " and visible = true " : " ") +
|
|
|
|
|
"order by posted asc";
|
|
|
|
|
cmd.Parameters.AddWithValue ("appname", applicationName);
|
|
|
|
|
cmd.Parameters.AddWithValue ("id", postid);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
using (NpgsqlDataReader rdr = cmd.ExecuteReader()) {
|
|
|
|
|
using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) {
|
|
|
|
|
while (rdr.Read ()) {
|
|
|
|
|
Comment c = new Comment();
|
|
|
|
|
Comment c = new Comment ();
|
|
|
|
|
c.CommentText = rdr.GetString (rdr.GetOrdinal ("bcontent"));
|
|
|
|
|
c.From = rdr.GetString (rdr.GetOrdinal ("username"));
|
|
|
|
|
c.Modified = rdr.GetDateTime (rdr.GetOrdinal ("modified"));
|
|
|
|
|
c.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
|
|
|
|
c.Visible = rdr.GetBoolean (rdr.GetOrdinal ("visible"));
|
|
|
|
|
c.PostId = postid;
|
|
|
|
|
c.Id = rdr.GetInt64(rdr.GetOrdinal("_id"));
|
|
|
|
|
c.Id = rdr.GetInt64 (rdr.GetOrdinal ("_id"));
|
|
|
|
|
cmts.Add (c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cmts.ToArray();
|
|
|
|
|
return cmts.ToArray ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the post.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -112,9 +116,9 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
/// <param name="visible">If set to <c>true</c> visible.</param>
|
|
|
|
|
/// <param name="cids">Circle identifiers</param>
|
|
|
|
|
public override void UpdatePost (long postid, string title, string content,
|
|
|
|
|
bool visible, long [] cids)
|
|
|
|
|
bool visible, long[] cids)
|
|
|
|
|
{
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection(connectionString)) {
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
|
cmd.CommandText =
|
|
|
|
|
@ -131,10 +135,11 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
cmd.ExecuteNonQuery ();
|
|
|
|
|
}
|
|
|
|
|
cnx.Close();
|
|
|
|
|
cnx.Close ();
|
|
|
|
|
}
|
|
|
|
|
UpdatePostCircles (postid, cids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes the post.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -146,9 +151,10 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
cmd.CommandText = "delete from blog where _id = :id";
|
|
|
|
|
cmd.Parameters.AddWithValue ("id", postid);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
cmd.ExecuteNonQuery ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Comment the specified from, postid and content.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -158,13 +164,13 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
public override long Comment (string from, long postid, string content)
|
|
|
|
|
{
|
|
|
|
|
if (from == null)
|
|
|
|
|
throw new ArgumentNullException("from");
|
|
|
|
|
throw new ArgumentNullException ("from");
|
|
|
|
|
if (content == null)
|
|
|
|
|
throw new ArgumentNullException("content");
|
|
|
|
|
throw new ArgumentNullException ("content");
|
|
|
|
|
bool visible = AutoValidatesComments;
|
|
|
|
|
using (NpgsqlConnection cnx=
|
|
|
|
|
new NpgsqlConnection(connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
|
|
|
|
using (NpgsqlConnection cnx =
|
|
|
|
|
new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "insert into comment (postid,bcontent," +
|
|
|
|
|
"modified,posted,visible,username,applicationname)" +
|
|
|
|
|
"values (:postid,:bcontent,:modified,:posted," +
|
|
|
|
|
@ -178,9 +184,10 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
cmd.Parameters.AddWithValue ("username", from);
|
|
|
|
|
cmd.Parameters.AddWithValue ("appname", applicationName);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
return (long) cmd.ExecuteScalar();
|
|
|
|
|
return (long)cmd.ExecuteScalar ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Validates the comment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -189,6 +196,7 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the comment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -202,6 +210,7 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool autoValidateComment = true;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether this <see cref="Npgsql.Web.Blog.NpgsqlBlogProvider"/> auto validate comment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -211,7 +220,7 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
return autoValidateComment;
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
autoValidateComment=value;
|
|
|
|
|
autoValidateComment = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -227,6 +236,7 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initialize the specified name and config.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -240,10 +250,12 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
config.Remove ("connectionStringName");
|
|
|
|
|
applicationName = config ["applicationName"];
|
|
|
|
|
config.Remove ("applicationName");
|
|
|
|
|
defaultPageSize = int.Parse ( config ["pageLen"] ?? "10") ;
|
|
|
|
|
defaultPageSize = int.Parse (config ["pageLen"] ?? "10");
|
|
|
|
|
base.Initialize (name, config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region implemented abstract members of BlogProvider
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the post.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -252,14 +264,14 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
public override BlogEntry GetPost (long postid)
|
|
|
|
|
{
|
|
|
|
|
BlogEntry be = null;
|
|
|
|
|
using (NpgsqlConnection cnx=new NpgsqlConnection(connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "select username, title, bcontent, modified, posted, visible, photo from blog " +
|
|
|
|
|
"where applicationname = :appname and _id = :id";
|
|
|
|
|
cmd.Parameters.AddWithValue ("appname", applicationName);
|
|
|
|
|
cmd.Parameters.AddWithValue ("id", postid);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
using (NpgsqlDataReader rdr = cmd.ExecuteReader()) {
|
|
|
|
|
using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) {
|
|
|
|
|
if (rdr.Read ()) {
|
|
|
|
|
be = new BlogEntry ();
|
|
|
|
|
be.Title = rdr.GetString (rdr.GetOrdinal ("title"));
|
|
|
|
|
@ -269,16 +281,18 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
be.Posted = rdr.GetDateTime (rdr.GetOrdinal ("posted"));
|
|
|
|
|
be.Visible = rdr.GetBoolean (rdr.GetOrdinal ("visible"));
|
|
|
|
|
int oph = rdr.GetOrdinal ("photo");
|
|
|
|
|
if (!rdr.IsDBNull(oph))
|
|
|
|
|
if (!rdr.IsDBNull (oph))
|
|
|
|
|
be.Photo = rdr.GetString (oph);
|
|
|
|
|
be.Id = postid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (be!=null) Populate (be);
|
|
|
|
|
if (be != null)
|
|
|
|
|
Populate (be);
|
|
|
|
|
return be;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes the comment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -292,10 +306,11 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
cmd.CommandText = "delete from comment where _id = :id returning postid";
|
|
|
|
|
cmd.Parameters.AddWithValue ("id", cmtid);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
postid = (long) cmd.ExecuteScalar ();
|
|
|
|
|
postid = (long)cmd.ExecuteScalar ();
|
|
|
|
|
}
|
|
|
|
|
return postid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the post.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -304,13 +319,13 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
/// <param name="title">Title.</param>
|
|
|
|
|
public override UUTBlogEntryCollection GetPost (string username, string title)
|
|
|
|
|
{
|
|
|
|
|
UUTBlogEntryCollection bec = new UUTBlogEntryCollection (username,title);
|
|
|
|
|
UUTBlogEntryCollection bec = new UUTBlogEntryCollection (username, title);
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "select _id,bcontent,modified,posted,visible,photo from blog " +
|
|
|
|
|
"where applicationname = :appname and username = :username and title = :title";
|
|
|
|
|
cmd.Parameters.AddWithValue ("appname", NpgsqlDbType.Varchar, applicationName);
|
|
|
|
|
cmd.Parameters.AddWithValue ("username", NpgsqlDbType.Varchar ,username);
|
|
|
|
|
cmd.Parameters.AddWithValue ("username", NpgsqlDbType.Varchar, username);
|
|
|
|
|
cmd.Parameters.AddWithValue ("title", NpgsqlDbType.Varchar, title);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
cmd.Prepare ();
|
|
|
|
|
@ -352,13 +367,14 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
be.Tags = tags.ToArray ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (bec!=null) Populate (bec);
|
|
|
|
|
if (bec != null)
|
|
|
|
|
Populate (bec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetCirclesOn(BlogEntry be)
|
|
|
|
|
private void SetCirclesOn (BlogEntry be)
|
|
|
|
|
{
|
|
|
|
|
List<long> circles = new List<long> ();
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
@ -380,12 +396,12 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
/// Removes the tag.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tagid">Tagid.</param>
|
|
|
|
|
public override void DropTag(long tagid)
|
|
|
|
|
public override void DropTag (long tagid)
|
|
|
|
|
{
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "DELETE from public.tag where _id = :tid";
|
|
|
|
|
cmd.Parameters.AddWithValue("tagid",tagid);
|
|
|
|
|
cmd.Parameters.AddWithValue ("tagid", tagid);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
cmd.ExecuteNonQuery ();
|
|
|
|
|
cnx.Close ();
|
|
|
|
|
@ -393,7 +409,9 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string SelectTagsSql = "SELECT tag.name, tag._id FROM public.tag WHERE name like :name";
|
|
|
|
|
private IEnumerable<string> GetSuggestion (string pattern) {
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> GetSuggestion (string pattern)
|
|
|
|
|
{
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = SelectTagsSql;
|
|
|
|
|
@ -402,7 +420,8 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string InsertTagSql = "INSERT INTO tag (name) VALUES (:name) returning _id";
|
|
|
|
|
private void InsertTag(long postid, long tagid)
|
|
|
|
|
|
|
|
|
|
private void InsertTag (long postid, long tagid)
|
|
|
|
|
{
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
@ -411,7 +430,7 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private long GetTagId(string tagname)
|
|
|
|
|
private long GetTagId (string tagname)
|
|
|
|
|
{
|
|
|
|
|
long id = 0;
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
@ -419,20 +438,30 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
cmd.CommandText = "SELECT tag._id FROM public.tag WHERE name = :name";
|
|
|
|
|
cmd.Parameters.AddWithValue ("name", tagname);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
id = (long) cmd.ExecuteScalar ();
|
|
|
|
|
id = (long)cmd.ExecuteScalar ();
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
private long GetOrCreateTagId(string tagname)
|
|
|
|
|
|
|
|
|
|
private long GetOrCreateTagId (string tagname)
|
|
|
|
|
{
|
|
|
|
|
long id = 0;
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
|
|
|
|
try {
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "SELECT tag._id FROM public.tag WHERE name = :name";
|
|
|
|
|
cmd.Parameters.AddWithValue ("name", tagname);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
id = (long)cmd.ExecuteScalar ();
|
|
|
|
|
}
|
|
|
|
|
} catch (NullReferenceException) {
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "SELECT tag._id FROM public.tag WHERE name = :name;\n" +
|
|
|
|
|
"IF NOT FOUND THEN INSERT INTO tag (name) values (:name) RETURNING _id; ENDIF;\n";
|
|
|
|
|
cmd.CommandText = "INSERT INTO public.tag(name) VALUES (:name) RETURNING _id";
|
|
|
|
|
cmd.Parameters.AddWithValue ("name", tagname);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
id = (long) cmd.ExecuteScalar ();
|
|
|
|
|
id = (long)cmd.ExecuteScalar ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
@ -441,12 +470,15 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
|
|
|
|
|
private static string SelectPostTagsSql = "SELECT tag.name FROM public.tag, public.tagged\n" +
|
|
|
|
|
"WHERE tag._id = tagged.tagid AND tagged.postid = :pid \n";
|
|
|
|
|
private void SetTagsOn(BlogEntryCollection bec){
|
|
|
|
|
|
|
|
|
|
private void SetTagsOn (BlogEntryCollection bec)
|
|
|
|
|
{
|
|
|
|
|
foreach (BlogEntry be in bec) {
|
|
|
|
|
SetTagsOn (be);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void SetTagsOn(BlogEntry be)
|
|
|
|
|
|
|
|
|
|
private void SetTagsOn (BlogEntry be)
|
|
|
|
|
{
|
|
|
|
|
List<string> tags = new List<string> ();
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
@ -464,16 +496,18 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Assert(bec!=null);
|
|
|
|
|
private void Populate(BlogEntryCollection bec)
|
|
|
|
|
private void Populate (BlogEntryCollection bec)
|
|
|
|
|
{
|
|
|
|
|
foreach (BlogEntry be in bec) Populate(be);
|
|
|
|
|
foreach (BlogEntry be in bec)
|
|
|
|
|
Populate (be);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Populate(BlogEntry be)
|
|
|
|
|
private void Populate (BlogEntry be)
|
|
|
|
|
{
|
|
|
|
|
SetTagsOn (be);
|
|
|
|
|
SetCirclesOn (be);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Post the specified username, title, content and visible.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -482,15 +516,15 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
/// <param name="content">Content.</param>
|
|
|
|
|
/// <param name="visible">If set to <c>true</c> visible.</param>
|
|
|
|
|
/// <param name="circles">.</param>
|
|
|
|
|
public override long Post (string username, string title, string content, bool visible, long [] circles)
|
|
|
|
|
public override long Post (string username, string title, string content, bool visible, long[] circles)
|
|
|
|
|
{
|
|
|
|
|
long pid = 0;
|
|
|
|
|
if (username == null)
|
|
|
|
|
throw new ArgumentNullException("username");
|
|
|
|
|
throw new ArgumentNullException ("username");
|
|
|
|
|
if (title == null)
|
|
|
|
|
throw new ArgumentNullException("title");
|
|
|
|
|
throw new ArgumentNullException ("title");
|
|
|
|
|
if (content == null)
|
|
|
|
|
throw new ArgumentNullException("content");
|
|
|
|
|
throw new ArgumentNullException ("content");
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "insert into blog (title,bcontent,modified,posted,visible,username,applicationname)" +
|
|
|
|
|
@ -511,12 +545,13 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
UpdatePostCircles (pid, circles);
|
|
|
|
|
return pid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the post photo.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pid">Pid.</param>
|
|
|
|
|
/// <param name="photo">Photo.</param>
|
|
|
|
|
public override void UpdatePostPhoto ( long pid, string photo)
|
|
|
|
|
public override void UpdatePostPhoto (long pid, string photo)
|
|
|
|
|
{
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
@ -530,7 +565,7 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePostCircles( long pid, long[] circles)
|
|
|
|
|
private void UpdatePostCircles (long pid, long[] circles)
|
|
|
|
|
{
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) {
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
@ -539,8 +574,8 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
cmd.Parameters.AddWithValue ("pid", pid);
|
|
|
|
|
cmd.ExecuteNonQuery ();
|
|
|
|
|
}
|
|
|
|
|
if (circles!=null)
|
|
|
|
|
if (circles.Length>0)
|
|
|
|
|
if (circles != null)
|
|
|
|
|
if (circles.Length > 0)
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "insert into blog_access (post_id,circle_id) values (:pid,:cid)";
|
|
|
|
|
cmd.Parameters.AddWithValue ("pid", NpgsqlTypes.NpgsqlDbType.Bigint, pid);
|
|
|
|
|
@ -554,6 +589,7 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
cnx.Close ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds the post.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -568,8 +604,8 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
{
|
|
|
|
|
BlogEntryCollection c = new BlogEntryCollection ();
|
|
|
|
|
totalRecords = 0;
|
|
|
|
|
using (NpgsqlConnection cnx=new NpgsqlConnection(connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
if (readersName != null) {
|
|
|
|
|
cmd.CommandText = "select _id, title,bcontent, modified," +
|
|
|
|
|
"posted,username,visible,photo " +
|
|
|
|
|
@ -624,11 +660,11 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
|
|
|
|
|
cmd.CommandText += " order by posted desc";
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
using (NpgsqlDataReader rdr = cmd.ExecuteReader()) {
|
|
|
|
|
using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) {
|
|
|
|
|
// pageIndex became one based
|
|
|
|
|
int firstrec = pageIndex * pageSize;
|
|
|
|
|
int lastrec = firstrec + pageSize - 1;
|
|
|
|
|
while (rdr.Read()) {
|
|
|
|
|
while (rdr.Read ()) {
|
|
|
|
|
if (totalRecords >= firstrec && totalRecords <= lastrec) {
|
|
|
|
|
BlogEntry be = new BlogEntry ();
|
|
|
|
|
be.Title = rdr.GetString (rdr.GetOrdinal ("title"));
|
|
|
|
|
@ -650,10 +686,12 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
rdr.Close ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (c!=null) Populate (c);
|
|
|
|
|
if (c != null)
|
|
|
|
|
Populate (c);
|
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes the post.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -661,20 +699,21 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
/// <param name="title">Title.</param>
|
|
|
|
|
public override void RemoveTitle (string username, string title)
|
|
|
|
|
{
|
|
|
|
|
using (NpgsqlConnection cnx=new NpgsqlConnection(connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "delete from blog where username = :username and applicationname = :appname and title=:title";
|
|
|
|
|
cmd.Parameters.AddWithValue ("username",username);
|
|
|
|
|
cmd.Parameters.AddWithValue ("username", username);
|
|
|
|
|
cmd.Parameters.AddWithValue ("appname", applicationName);
|
|
|
|
|
cmd.Parameters.AddWithValue ("title",title);
|
|
|
|
|
cmd.Parameters.AddWithValue ("title", title);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
cmd.ExecuteNonQuery ();
|
|
|
|
|
cnx.Close();
|
|
|
|
|
cnx.Close ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int defaultPageSize = 10;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Lasts the posts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -682,23 +721,23 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
/// <param name="pageIndex">Page index.</param>
|
|
|
|
|
/// <param name="pageSize">Page size.</param>
|
|
|
|
|
/// <param name="totalRecords">Total records.</param>
|
|
|
|
|
public override BlogEntryCollection LastPosts(int pageIndex, int pageSize, out int totalRecords)
|
|
|
|
|
public override BlogEntryCollection LastPosts (int pageIndex, int pageSize, out int totalRecords)
|
|
|
|
|
{
|
|
|
|
|
BlogEntryCollection c = new BlogEntryCollection ();
|
|
|
|
|
using (NpgsqlConnection cnx=new NpgsqlConnection(connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
|
|
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
|
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
|
|
|
cmd.CommandText = "select * " +
|
|
|
|
|
"from blog where applicationname = :appname and visible = true " +
|
|
|
|
|
" order by posted desc limit :len" ;
|
|
|
|
|
" order by posted desc limit :len";
|
|
|
|
|
|
|
|
|
|
cmd.Parameters.AddWithValue ("appname", applicationName);
|
|
|
|
|
cmd.Parameters.AddWithValue ("len", defaultPageSize*10);
|
|
|
|
|
cmd.Parameters.AddWithValue ("len", defaultPageSize * 10);
|
|
|
|
|
cnx.Open ();
|
|
|
|
|
using (NpgsqlDataReader rdr = cmd.ExecuteReader()) {
|
|
|
|
|
using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) {
|
|
|
|
|
totalRecords = 0;
|
|
|
|
|
int firstrec = pageIndex * pageSize;
|
|
|
|
|
int lastrec = firstrec + pageSize - 1;
|
|
|
|
|
while (rdr.Read()) {
|
|
|
|
|
while (rdr.Read ()) {
|
|
|
|
|
if (totalRecords >= firstrec && totalRecords <= lastrec) {
|
|
|
|
|
BlogEntry be = new BlogEntry ();
|
|
|
|
|
be.Id = rdr.GetInt64 (rdr.GetOrdinal ("_id"));
|
|
|
|
|
@ -719,9 +758,11 @@ namespace Npgsql.Web.Blog
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (c!=null) Populate (c);
|
|
|
|
|
if (c != null)
|
|
|
|
|
Populate (c);
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|