Exemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="blogId"></param>
 /// <returns></returns>
 public ActionResult Edit(int? blogId = null)
 {
     if (User.Identity.IsAuthenticated == false)
     {
         Response.Redirect("~/Home/Index");
     }
     Blog blog = new Blog();
     if (blogId != null) { blog = Blog.Get(Convert.ToInt32(blogId)); }
     return View(blog);
 }
Exemplo n.º 2
0
        public JsonResult Save(string blog_description, string blog_title, string blog_hidden, string blog_html, string blog_start_date, string blog_end_date, int? blog_id = null)
        {
            Blog blog = new Blog();
            if (blog_id != null) {
                blog = Blog.Get (Convert.ToInt32 (blog_id));
                blog.BlogPostDate = DateTime.Now;
            } else {
                blog.BlogAuthor = User.Identity.Name;
            }

            blog.BlogDescription = blog_description;
            blog.BlogHidden = blog_hidden == "yes" ? true : false;
            blog.BlogTitle = blog_title;
            blog.BlogHtml = blog_html;
            if (blog_start_date.Length > 0) {
                blog.BlogStartDate = Convert.ToDateTime(blog_start_date);
            }
            if (blog_end_date.Length > 0) {
                blog.BlogEndDate = Convert.ToDateTime(blog_end_date);
            }

            blog.Save();
            return Json (blog);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="blogId"></param>
 /// <returns></returns>
 public ActionResult View(int? blogId = null)
 {
     Blog blog = new Blog();
     if (blogId != null) {
         blog = Blog.Get (Convert.ToInt32 (blogId));
     } else {
         RedirectToAction ("Home", "Blog");
     }
     return View(blog); // PartialView to return Partial
 }
Exemplo n.º 4
0
Arquivo: Blog.cs Projeto: jfbomber/kk
        public static void LoadParameters(SqliteCommand cmd, Blog blog)
        {
            string query = cmd.CommandText;

            if (query.IndexOf("@blog_id") != -1) { cmd.Parameters.Add("@blog_id", System.Data.DbType.String).Value = Convert.ToInt32(blog.BlogID); }

            cmd.Parameters.Add("@blog_html", System.Data.DbType.String).Value = blog.BlogHtml;
            cmd.Parameters.Add("@blog_hidden", System.Data.DbType.Int32).Value = Convert.ToInt32(blog.BlogHidden);

            if (blog.BlogDescription != null) { cmd.Parameters.Add("@blog_description", System.Data.DbType.String).Value = blog.BlogDescription; }
            else { cmd.Parameters.Add("@blog_description", System.Data.DbType.String).Value = DBNull.Value;  }

            if (blog.BlogTitle != null) { cmd.Parameters.Add("@blog_title", System.Data.DbType.String).Value = blog.BlogTitle; }
            else { cmd.Parameters.Add("@blog_title", System.Data.DbType.String).Value = DBNull.Value; }

            if (blog.BlogStartDate != null) { cmd.Parameters.Add("@blog_start_date", System.Data.DbType.DateTime).Value = blog.BlogStartDate; }
            else { cmd.Parameters.Add("@blog_start_date", System.Data.DbType.DateTime).Value = DBNull.Value; }

            if (blog.BlogEndDate != null) { cmd.Parameters.Add("@blog_end_date", System.Data.DbType.DateTime).Value = blog.BlogEndDate; }
            else { cmd.Parameters.Add("@blog_end_date", System.Data.DbType.DateTime).Value = DBNull.Value; }

            if (blog.BlogAuthor != null) { cmd.Parameters.Add("@blog_author", System.Data.DbType.String).Value = blog.BlogAuthor; }
            else { cmd.Parameters.Add("@blog_author", System.Data.DbType.String).Value = DBNull.Value; }
        }
Exemplo n.º 5
0
Arquivo: Blog.cs Projeto: jfbomber/kk
        /// <summary>
        /// Gets a list if blogs
        /// </summary>
        /// <returns>List of blogs</returns>
        public static List<Blog> GetAll(int? offset, int? limit)
        {
            List<Blog> blogs = new List<Blog>();

            string query = String.Format("SELECT * FROM kk_blog ORDER BY blog_id DESC ");
            if (limit != null) {
                query += String.Format ("LIMIT {0} ", limit);
            }

            if (offset != null) {
                query += String.Format ("OFFSET {0} ", offset);
            }

            // get database connection
            using (SqliteConnection conn = new SqliteConnection (ConnString))
            {
                conn.Open();
                // execute cmd
                using (SqliteCommand cmd = new SqliteCommand(query, conn))
                {
                    // user reader to fill data
                    using (SqliteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Blog blog = new Blog();
                            Blog.DBFill(reader, blog);
                            blogs.Add(blog);
                        }
                    }
                }
            }
            return blogs;
        }
Exemplo n.º 6
0
Arquivo: Blog.cs Projeto: jfbomber/kk
        /// <summary>
        /// Gets as single Blob by id
        /// </summary>
        /// <param name="projectId"></param>
        /// <returns></returns>
        public static Blog Get(int blogId)
        {
            Blog blog = new Blog();
            string query = "SELECT * FROM kk_blog WHERE blog_id = @blog_id;";
            // get database connection
            using (SqliteConnection conn = new SqliteConnection(ConnString))
            {
                conn.Open();
                // execute cmd
                using (SqliteCommand cmd = new SqliteCommand(query, conn))
                {
                    cmd.Parameters.Add("@blog_id", System.Data.DbType.Int32).Value = blogId;
                    // user reader to fill data
                    using (SqliteDataReader reader = cmd.ExecuteReader())
                    {
                        reader.Read();
                        Blog.DBFill(reader, blog);
                    }

                }
            }
            return blog;
        }
Exemplo n.º 7
0
Arquivo: Blog.cs Projeto: jfbomber/kk
        /// <summary>
        /// Insert
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="project"></param>
        public static void DBFill(SqliteDataReader reader, Blog blog)
        {
            blog.BlogID = Convert.ToInt32(reader["blog_id"]);
            blog.BlogTitle = reader["blog_title"].ToString();
            blog.BlogDescription = reader["blog_description"].ToString();
            blog.BlogHtml = reader["blog_html"].ToString();
            blog.BlogPostDate = Convert.ToDateTime(reader["blog_post_date"]);

            if (reader["blog_start_date"] != DBNull.Value) { blog.BlogStartDate = Convert.ToDateTime(reader["blog_start_date"]); }
            if (reader["blog_end_date"] != DBNull.Value) { blog.BlogEndDate = Convert.ToDateTime(reader["blog_end_date"]); }
            if (reader["blog_author"] != DBNull.Value) {
                blog.BlogAuthor = reader["blog_author"].ToString();
                blog.BlogAuthorData = KK.User.GetByUserName (blog.BlogAuthor);
            }
        }