Esempio n. 1
0
        /// <summary>
        /// Loads blog from DB by specified id or username.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="username">The username.</param>
        /// <returns>Blog object.</returns>
        private static Blog Load(int id, string username)
        {
            string cacheKey = String.Format("Blog_Load_{0}_{1}", id, username);
            if (HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null)
            {
                return HttpContext.Current.Cache[cacheKey] as Blog;
            }

            //using (var conn = Config.DB.Open())
            {
                using (var reader = SqlHelper.GetDB().ExecuteReader("LoadBlog", id, username))
                {

                    if (reader.Read())
                    {
                        Blog blog = new Blog();

                        blog.id = (int) reader["Id"];
                        blog.username = (string) reader["Username"];
                        blog.name = (string) reader["Name"];
                        blog.description = (string) reader["Description"];
                        blog.dateCreated = (DateTime) reader["DateCreated"];
                        if (reader["Settings"] is string)
                            blog.settings = (string) reader["Settings"];

                        reader.Close();

                        if (HttpContext.Current != null)
                        {
                            HttpContext.Current.Cache.Insert(cacheKey, blog, null, Cache.NoAbsoluteExpiration,
                                                             TimeSpan.FromMinutes(30), CacheItemPriority.NotRemovable,
                                                             null);
                        }

                        return blog;
                    }
                    else
                        return null;
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Creates blog for the specified username.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <returns></returns>
 public static Blog Create(string username)
 {
     Blog blog = new Blog();
     blog.id = -1;
     blog.username = username;
     return blog;
 }