Exemple #1
0
        public void GetPosts()
        {
            string strCon = System.Web
                            .Configuration
                            .WebConfigurationManager
                            .ConnectionStrings["WingtipToys"].ConnectionString;

            SqlConnection conn = new SqlConnection(strCon);

            conn.Open();
            SqlCommand     cmd = new SqlCommand("SELECT * FROM[POSTS] ORDER BY [date] DESC", conn);
            DataSet        ds  = new DataSet();
            SqlDataAdapter da  = new SqlDataAdapter(cmd);

            da.Fill(ds);
            BlogPosts.DataSource = ds;
            BlogPosts.DataBind();

            /*
             * List<Post> posts = new List<Post>();
             * String sql = "SELECT * FROM [POSTS] ORDER BY [date]";
             *
             * string strCon = System.Web
             *                    .Configuration
             *                    .WebConfigurationManager
             *                    .ConnectionStrings["SocialSiteConnectionString"].ConnectionString;
             *
             * SqlConnection conn = new SqlConnection(strCon);
             * SqlCommand comm = new SqlCommand(sql, conn);
             * conn.Open();
             * SqlDataReader nwReader = comm.ExecuteReader();
             * while( nwReader.Read() )
             * {
             *  posts.Add(new Post
             *  {
             *      PostId = nwReader.GetInt32(0),
             *      title = nwReader.GetString(1),
             *      text = nwReader.GetString(2),
             *      date = nwReader.GetDateTime(3)
             *  });
             * }
             */
        }
Exemple #2
0
        protected void Page_Init(object sender, EventArgs e)
        {
            var templateTopAndBottomSegments = CurrentMediaDetail.GetTemplateTopAndBottomSegments(this);

            if (templateTopAndBottomSegments.Count > 1)
            {
                TemplateTopSegment.Controls.Add(templateTopAndBottomSegments.ElementAt(0));
                TemplateBottomSegment.Controls.Add(templateTopAndBottomSegments.ElementAt(1));
            }

            var blogPosts  = BaseMapper.GetDataModel().MediaDetails.Where(i => i.MediaType.Name == "BlogPost" && i.HistoryVersionNumber == 0);
            var categories = BaseMapper.GetDataModel().MediaDetails.Where(i => i.MediaType.Name == "BlogCategory" && i.HistoryVersionNumber == 0);

            BlogCategories.DataSource = categories.ToList().Where(i => i.CanRender).ToList();
            BlogCategories.DataBind();

            if (CurrentMediaDetail.MediaType.Name == "BlogCategory")
            {
                blogPosts = blogPosts.Where(i => i.Media.ParentMediaID == CurrentMediaDetail.MediaID);
            }

            BlogPosts.DataSource = blogPosts.ToList().Where(i => i.CanRender).OrderByDescending(i => i.PublishDate).ToList();
            BlogPosts.DataBind();
        }