public static Int64 Create(wp_post item, string connectionString, IDbConnection connection, IDbTransaction transaction) { var _connection = GetConnection(connection, connectionString); Int64 result = _connection.Insert <wp_post>(item, transaction: transaction).Value; return(result); }
public static wp_post GetPost(string id, string connectionString, IDbConnection connection, IDbTransaction transaction) { wp_post result = null; var _connection = GetConnection(connection, connectionString); var sQuery = "SELECT TOP 10 * FROM wp_post WHERE (post_name = @post_name) "; result = _connection.Query <wp_post>(sQuery, new { post_name = id }, transaction: transaction).FirstOrDefault(); return(result); }
public static wp_post GetParentImage(string id, string connectionString, IDbConnection connection, IDbTransaction transaction) { wp_post result = null; var _connection = GetConnection(connection, connectionString); var sQuery = "SELECT * FROM wp_post WHERE ( (post_type = @post_type) AND (post_name = @post_name) AND (post_parent = 0) ) "; result = _connection.Query <wp_post>(sQuery, new { post_type = "image", post_name = id, }, transaction: transaction).FirstOrDefault(); return(result); }
public IActionResult Slug(string id) { @ViewData["Title"] = id; @ViewData["Tenant"] = this._tenant; @ViewData["Layout"] = this._tenant.Template; wp_post data = null; try { data = Posts.GetPost(id, this._connectionString, null, null); } catch (Exception) { } @ViewData["Title"] = string.Concat((((data != null) && !string.IsNullOrEmpty(data.post_title)) ? data.post_title : id), " - ", this._tenant.Name); return(View("Details", data)); }
public static long CreatePost(wp_user user, string title, string dbid, string description, string type) { using (var ctx = new DatabaseContext(Config.DB_CONNECTION_STRING)) { var post = new wp_post { post_title = title, post_type = type, post_name = dbid, post_status = "publish", post_content = description, post_excerpt = String.Empty, to_ping = String.Empty, pinged = String.Empty, post_content_filtered = String.Empty, comment_status = "open", ping_status = "open", post_password = String.Empty, post_parent = 0, guid = String.Empty, menu_order = 0, post_mime_type = String.Empty, comment_count = 0, post_author = user.ID, post_date = DateTime.Now, post_date_gmt = DateTime.Now, post_modified = DateTime.Now, post_modified_gmt = DateTime.Now }; ctx.WP_Posts.Add(post); ctx.SaveChanges(); return(post.ID); } }
public static wp_image SaveImageFromStream( byte [] upload, Int64 id, string category, string url, string name, string connectionString) { Int64? parentPostId = null; wp_image image = null; if (!string.IsNullOrEmpty(category) && !string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(name)) { var post_parent = Posts.GetParentImage(category, connectionString, null, null); if (post_parent == null) { post_parent = new wp_post() { post_name = category, post_parent = 0, post_content = category, comment_count = 0, guid = Guid.NewGuid().ToString(), post_status = "active", post_type = "image", post_date = DateTime.Now, post_title = category, to_ping = "", post_date_gmt = DateTime.Now, post_modified = DateTime.Now, post_modified_gmt = DateTime.Now, site_id = 1, comment_status = "", post_mime_type = "", post_password = "", pinged = "", ping_status = "", post_author = 0, post_content_filtered = "", post_excerpt = "", }; parentPostId = Posts.Create(post_parent, connectionString, null, null); } else { parentPostId = post_parent.ID; } if (parentPostId.HasValue) { if (upload != null && upload.Length > 0) { image = new wp_image() { category = category, url = url, name = name, site_id = 1, content = upload }; } else { image = Images.GetImageBytes(url, new wp_image() { category = category, url = url, name = name, site_id = 1 }); } using (var transaction = new System.Transactions.TransactionScope()) { image.category = category; // create a new image if (id == 0) { var newImageId = Images.Create(image, connectionString, null, null); var postChild = new wp_post() { post_parent = parentPostId.Value, post_name = newImageId.ToString(), post_content = category, post_category = category, post_status = "active", post_type = "image", post_date = DateTime.Now, post_title = category, comment_status = "", post_mime_type = "", guid = Guid.NewGuid().ToString(), post_author = 0, post_content_filtered = "", post_excerpt = "", to_ping = "", post_password = "", pinged = "", ping_status = "", post_date_gmt = DateTime.Now, post_modified = DateTime.Now, post_modified_gmt = DateTime.Now, comment_count = 0, site_id = 1, }; var newChildPostId = Posts.Create(postChild, connectionString, null, null); if (newImageId > 0 && newChildPostId > 0) { transaction.Complete(); } } else { // update an existing image var existing = Images.Get(id, connectionString, null, null); existing.name = name; existing.category = category; existing.url = url; existing.content = upload; Images.Update(id, existing, connectionString, null, null); transaction.Complete(); } } } } return(image); }