Beispiel #1
0
 /// <summary>
 /// Returns a view to edit a Content object
 /// </summary>
 /// <param name="contentID"></param>
 /// <returns></returns>
 public ActionResult Edit(int? contentID = null)
 {
     KK.Models.Content content = new Content();
     if (contentID != null)
     {
         if (!Request.IsAuthenticated || !User.IsInRole("admin")) {
             return RedirectToAction("Index", "Home");
         }
         content = KK.Models.Content.Get(Convert.ToInt32(contentID));
     }
     return PartialView(content);
 }
Beispiel #2
0
        public ContentResult Save(string contentController, string contentAction, string contentTitle, string contentHtml, int? contentID, int? photoID)
        {
            KK.Models.Content content = new Models.Content();
            if (contentID != null)
            {
                content = KK.Models.Content.Get(Convert.ToInt32(contentID));
            }
            else
            {
                content.ContentAdded = DateTime.Now;
                content.ContentAddedBy = User.Identity.Name;
            }
            content.ContentPhotoID = photoID;
            content.ContentUpdated = DateTime.Now;
            content.ContentUpdatedBy = User.Identity.Name;
            content.ContentAction = contentAction;
            content.ContentController = contentController;
            content.ContentTitle = contentTitle;
            content.ContentHtml = contentHtml;
            content.Save();

            string result = string.Format("{{ \"Result\" : \"success\", \"Data\" : {{ \"ContentID\" :{0} }} }}", content.ContentID);
            return new ContentResult { Content = result };
        }
Beispiel #3
0
        /// <summary>
        /// Gets as single project by id
        /// </summary>
        /// <param name="projectId"></param>
        /// <returns></returns>
        public static Content Get(string controller, string action, string title)
        {
            Content content = new Content();
            string query = @"SELECT * FROM kk_content
                            WHERE content_action = @action
                            AND content_controller = @controller AND content_title = @title";
            // get database connection
            using (SqliteConnection conn = new SqliteConnection(connectionString))
            {
                conn.Open();

                using (SqliteCommand cmd = new SqliteCommand(query, conn))
                {
                    cmd.Parameters.Add("@action", System.Data.DbType.String).Value = action;
                    cmd.Parameters.Add("@controller", System.Data.DbType.String).Value = controller;
                    cmd.Parameters.Add("@title", System.Data.DbType.String).Value = title;

                    // user reader to fill data
                    using (SqliteDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        Content.DBFill(reader, content);
                    }

                }
            }
            return content;
        }
Beispiel #4
0
        public static Content Get(int contentId)
        {
            Content content = new Content();
            string query = "SELECT * FROM kk_content WHERE content_id = @id;";
            // get database connection
            using (SqliteConnection conn = new SqliteConnection(connectionString))
            {
                conn.Open();
                // execute cmd
                using (SqliteCommand cmd = new SqliteCommand(query, conn))
                {
                    cmd.Parameters.Add("@id", System.Data.DbType.Int32).Value = contentId;
                    // user reader to fill data
                    using (SqliteDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        Content.DBFill(reader, content);
                    }

                }
            }
            return content;
        }
Beispiel #5
0
        /// <summary>
        /// Insert
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="project"></param>
        public static void DBFill(SqliteDataReader reader, Content content)
        {
            content.ContentID = Convert.ToInt32(reader["content_id"]);
            content.ContentAction = reader["content_action"].ToString();
            content.ContentController = reader["content_controller"].ToString();

            if (reader["content_title"] != DBNull.Value) { content.ContentTitle = reader["content_title"].ToString(); }
            if (reader["content_photo_id"] != DBNull.Value) { content.ContentPhotoID = Convert.ToInt32(reader["content_photo_id"]); }

            content.ContentHtml = HttpUtility.UrlDecode(reader["content_html"].ToString(), System.Text.Encoding.Default);
            content.ContentUpdatedBy = reader["content_updated_by"].ToString();
            content.ContentUpdated = Convert.ToDateTime(reader["content_updated_dt"]);
            content.ContentAddedBy = reader["content_added_by"].ToString();
            content.ContentAdded = Convert.ToDateTime(reader["content_added_dt"]);
            content.ContentItems = ContentItem.GetAll(Convert.ToInt32(content.ContentID));
        }