예제 #1
0
        public List <StaticPage> GetAllStaticPages()
        {
            var staticPages = new List <StaticPage>();

            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand("Select p.UserId, p.StaticPageContent, p.StatusID, s.StatusType, p.DateOfPageCreation, p.StaticPageTitle, p.StaticPageID from StaticPage p inner join [Status] s  on p.StatusID= s.StatusID order by p.DateOfPageCreation desc", cn);
                cn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var staticPage = new StaticPage()
                        {
                            Status = new Status(),
                            User   = new User()
                        };
                        staticPage.User.UserId        = dr.GetString(0);
                        staticPage.StaticPageContent  = dr.GetString(1);
                        staticPage.Status.StatusID    = dr.GetInt32(2);
                        staticPage.Status.StatusType  = dr.GetString(3);
                        staticPage.DateOfPageCreation = dr.GetDateTime(4);
                        staticPage.StaticPageTitle    = dr.GetString(5);
                        staticPage.StaticPageID       = dr.GetInt32(6);

                        staticPages.Add(staticPage);
                    }
                }
            }
            var repo = new UserRepo();

            foreach (var page in staticPages)
            {
                var id = page.User.UserId;
                page.User        = repo.GetUserById(id);
                page.User.UserId = id;
            }
            return(staticPages);
        }
예제 #2
0
        public List <BlogPost> GetAllBlogPosts()
        {
            var blogPosts = new List <BlogPost>();

            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand("Select b.UserID, b.PostContent,b.StatusID,s.StatusType, b.DateOfPost, b.PostTitle, b.BlogPostID from Blogpost b inner join [Status] s  on b.StatusID= s.StatusID order by b.DateOfPost desc", cn);
                cn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var blog = new BlogPost()
                        {
                            Status = new Status(),
                            User   = new User()
                        };
                        blog.User.UserId       = dr.GetString(0);
                        blog.PostContent       = dr.GetString(1);
                        blog.Status.StatusID   = dr.GetInt32(2);
                        blog.Status.StatusType = dr.GetString(3);
                        blog.DateOfPost        = dr.GetDateTime(4);
                        blog.PostTitle         = dr.GetString(5);
                        blog.BlogPostID        = dr.GetInt32(6);

                        blogPosts.Add(blog);
                    }
                }
            }
            var repo = new UserRepo();

            foreach (var blog in blogPosts)
            {
                var id = blog.User.UserId;
                blog.User        = repo.GetUserById(id);
                blog.User.UserId = id;
            }
            return(blogPosts);
        }
예제 #3
0
        public List<StaticPage> GetAllStaticPages()
        {
            var staticPages = new List<StaticPage>();
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand("Select p.UserId, p.StaticPageContent, p.StatusID, s.StatusType, p.DateOfPageCreation, p.StaticPageTitle, p.StaticPageID from StaticPage p inner join [Status] s  on p.StatusID= s.StatusID order by p.DateOfPageCreation desc", cn);
                cn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var staticPage = new StaticPage()
                        {
                            Status = new Status(),
                            User = new User()
                        };
                        staticPage.User.UserId = dr.GetString(0);
                        staticPage.StaticPageContent= dr.GetString(1);
                        staticPage.Status.StatusID = dr.GetInt32(2);
                        staticPage.Status.StatusType = dr.GetString(3);
                        staticPage.DateOfPageCreation = dr.GetDateTime(4);
                        staticPage.StaticPageTitle = dr.GetString(5);
                        staticPage.StaticPageID = dr.GetInt32(6);

                        staticPages.Add(staticPage);
                    }
                }

            }
            var repo = new UserRepo();
            foreach (var page in staticPages)
            {
                var id = page.User.UserId;
                page.User = repo.GetUserById(id);
                page.User.UserId = id;
            }
            return staticPages;
        }
예제 #4
0
        public List<BlogPost> GetAllBlogPosts()
        {
            var blogPosts = new List<BlogPost>();
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand("Select b.UserID, b.PostContent,b.StatusID,s.StatusType, b.DateOfPost, b.PostTitle, b.BlogPostID from Blogpost b inner join [Status] s  on b.StatusID= s.StatusID order by b.DateOfPost desc", cn);
                cn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var blog = new BlogPost()
                        {
                            Status = new Status(),
                            User = new User()
                        };
                        blog.User.UserId = dr.GetString(0);
                        blog.PostContent = dr.GetString(1);
                        blog.Status.StatusID = dr.GetInt32(2);
                        blog.Status.StatusType = dr.GetString(3);
                        blog.DateOfPost = dr.GetDateTime(4);
                        blog.PostTitle = dr.GetString(5);
                        blog.BlogPostID = dr.GetInt32(6);

                        blogPosts.Add(blog);
                    }
                }

            }
            var repo = new UserRepo();
            foreach (var blog in blogPosts)
            {
                var id = blog.User.UserId;
                blog.User = repo.GetUserById(id);
                blog.User.UserId = id;
            }

            return blogPosts;
        }