Exemplo n.º 1
0
 public Response()
 {
     Category = new Category();
     Categories = new List<Category>();
     HashTag = new HashTag();
     HashTags = new List<HashTag>();
     User = new User();
     BlogPost = new BlogPost();
     BlogPosts = new List<BlogPost>();
     Mce = new TinyMceClass();
 }
Exemplo n.º 2
0
        public List<BlogPost> GetAllBlogPosts()
        {
            List<BlogPost> posts = new List<BlogPost>();

            using (var cn = new SqlConnection(Settings.ConnectionString))
            {
                SqlCommand cmd = cn.CreateCommand();
                cmd.CommandText = "GetAllBlogPostsOrderByCategory";
                cmd.CommandType = CommandType.StoredProcedure;

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var hashTag = new HashTag();

                        hashTag.HashTagID = dr.GetInt32(7);
                        hashTag.HashTagName = dr.GetString(8);

                        var testPostID = dr.GetInt32(0);

                        var item = posts.Where(p => p.BlogPostID == testPostID).FirstOrDefault();

                        if (item == null)
                        {
                            BlogPost post = new BlogPost();
                            post.BlogPostID = testPostID;
                            post.Title = dr.GetString(1);
                            post.Body = dr.GetString(2);
                            post.PostDate = dr.GetDateTime(3);
                            post.Category.CategoryID = dr.GetInt32(4);
                            post.Status = dr.GetInt32(5);
                            post.Category.CategoryName = dr.GetString(6);
                            post.User.UserID = dr.GetString(9);
                            post.User.UserName = dr.GetString(10);

                            post.HashTags.Add(hashTag);

                            posts.Add(post);
                        }
                        else
                        {
                            item.HashTags.Add(hashTag);
                        }
                    }
                }
            }
            return posts;
        }
Exemplo n.º 3
0
        public ActionResult CreatePostPost(BlogPostVM blogPostVM)
        {
            _ops = new MVCBlogOps();

                var blogPost = new BlogPost();
                var userManager =
                    new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
                var user = userManager.FindById(User.Identity.GetUserId());
                if (User.IsInRole("Admin"))
                {
                    blogPostVM.blogPost.Status = 1; // 1 is Approved
                    blogPost.Status = blogPostVM.blogPost.Status;
                }
                else
                {
                    blogPostVM.blogPost.Status = 2; // 2 is Unapproved
                    blogPost.Status = blogPostVM.blogPost.Status;
                }

                blogPost.User.UserID = user.Id;
                blogPost.Title = blogPostVM.blogPost.Title;
                blogPost.Mce.Body = blogPostVM.blogPost.Mce.Body;
                blogPost.Category.CategoryID = blogPostVM.category.CategoryID;

                if (blogPostVM.tags == null)
                {
                    HashTag hashTag = new HashTag();
                    hashTag.HashTagName = "#freshfoods";
                    blogPost.HashTags.Add(hashTag);
                }
                else
                {
                    foreach (var item in blogPostVM.tags)
                    {
                        HashTag hashTag = new HashTag();
                        hashTag.HashTagName = item;
                        blogPost.HashTags.Add(hashTag);
                    }
                }

            _ops.SaveBlogPostToRepo(blogPost);

            return RedirectToAction("Index", "Home");
        }