public ContentResult ItemSave(string itemTitle, string itemHtml, int contentID, int? itemID, int? photoID, bool itemHidden = false) { KK.Models.ContentItem item = new Models.ContentItem(); if (itemID != null) { item = KK.Models.ContentItem.Get(Convert.ToInt32(itemID)); } else { item.ContentID = contentID; item.ItemAdded = DateTime.Now; item.ItemAddedBy = User.Identity.Name; } item.ItemPhotoID = photoID; item.ItemLastUpdated = DateTime.Now; item.ItemLastUpdatedBy = User.Identity.Name; item.ItemTitle = itemTitle; item.ItemHtml = itemHtml; item.Save(); string result = string.Format("{{ \"Result\" : \"success\", \"Data\" : {{ \"ItemID\" :{0}, \"ContentID\":{1} }} }}", item.ItemID, item.ContentID); return new ContentResult { Content = result }; }
/// <summary> /// Returns a view to edit a ContentItem object /// </summary> /// <param name="contentID"></param> /// <param name="itemID"></param> /// <returns></returns> public ActionResult ItemEdit(int? contentID = null, int? itemID = null) { KK.Models.ContentItem item = new ContentItem(); if (contentID != null) { item.ContentID = Convert.ToInt32(contentID); item.Content = KK.Models.Content.Get(Convert.ToInt32(contentID)); } if (itemID != null) { if (!Request.IsAuthenticated || !User.IsInRole("admin")) { return RedirectToAction("Index", "Home"); } item = KK.Models.ContentItem.Get(Convert.ToInt32(itemID)); item.Content = KK.Models.Content.Get(item.ContentID); } return PartialView(item); }
/// <summary> /// Gets as single project by id /// </summary> /// <param name="projectId"></param> /// <returns></returns> public static ContentItem Get(int itemId) { ContentItem contentItem = new ContentItem(); string query = "SELECT * FROM kk_content_item WHERE content_item_id = @content_item_id;"; // get database connection using (SqliteConnection conn = new SqliteConnection(connectionString)) { conn.Open(); // execute cmd using (SqliteCommand cmd = new SqliteCommand(query, conn)) { cmd.Parameters.Add("@content_item_id", System.Data.DbType.Int32).Value = itemId; // user reader to fill data using (SqliteDataReader reader = cmd.ExecuteReader()) { reader.Read(); ContentItem.DBFill(reader, contentItem); } } } return contentItem; }
/// <summary> /// Gets all project /// </summary> /// <returns>Array of projects</returns> public static List<ContentItem> GetAll(int contentID) { List<ContentItem> contentItems = new List<ContentItem>(); string query = "SELECT * FROM kk_content_item WHERE content_id = @content_id AND content_item_hidden = 0;"; // get database connection using (SqliteConnection conn = new SqliteConnection(connectionString)) { conn.Open(); // execute cmd using (SqliteCommand cmd = new SqliteCommand(query, conn)) { cmd.Parameters.Add("@content_id", System.Data.DbType.Int32).Value = contentID; // user reader to fill data using (SqliteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { ContentItem contentItem = new ContentItem(); ContentItem.DBFill(reader, contentItem); contentItems.Add(contentItem); } } } } return contentItems; }
/// <summary> /// Insert /// /// </summary> /// <param name="reader"></param> /// <param name="project"></param> public static void DBFill(SqliteDataReader reader, ContentItem contentItem) { contentItem.ItemID = Convert.ToInt32(reader["content_item_id"]); contentItem.ContentID = Convert.ToInt32(reader["content_id"]); contentItem.ItemTitle = reader["content_item_title"].ToString(); contentItem.ItemHtml = HttpUtility.UrlDecode(reader["content_item_html"].ToString(), System.Text.Encoding.Default); contentItem.ItemAddedBy = reader["content_item_added_by"].ToString(); contentItem.ItemLastUpdatedBy = reader["content_item_updated_by"].ToString(); if (reader["content_item_updated"] != DBNull.Value) { contentItem.ItemLastUpdated = Convert.ToDateTime(reader["content_item_updated"]); } if (reader["content_item_added"] != DBNull.Value) { contentItem.ItemAdded = Convert.ToDateTime(reader["content_item_added"]); } if (reader["content_item_photo_id"] != DBNull.Value) { contentItem.ItemPhotoID = Convert.ToInt32(reader["content_item_photo_id"]); } contentItem.ItemHidden = Convert.ToBoolean(reader["content_item_hidden"]); }