Exemplo n.º 1
0
        public ActionResult Index(DraftPostVM model)
        {
            var blogPost = new BlogPost();

            blogPost = model.NewPost;
            blogPost.PostContent = model.HtmlContent;
            if (model.NewPost.Status == null)
            {
                blogPost.Status = new Status()
                {
                    StatusID = 1

                };
            }
            else
            {
                blogPost.Status.StatusID = model.NewPost.Status.StatusID;
            }
            var ops = OperationsFactory.CreateBlogPostOps();
            var categoryOps = OperationsFactory.CreateCategoryOps();
            ops.SaveBlogPost(blogPost);
            categoryOps.SaveBlogPostCategory(model.SelectedCategoryIds,blogPost);

            return RedirectToAction("Index","Home");
        }
Exemplo n.º 2
0
        public void SaveBlogPostHashtags(List<int> hashtagIds, BlogPost blog)
        {
            var ops = OperationsFactory.CreateBlogPostOps();
            var list = ops.GetAllBlogPosts();
            var lastPost = list.FirstOrDefault(x => x.PostTitle == blog.PostTitle);

            if (lastPost != null)
                _repo.SaveBlogPostHashtags(hashtagIds, lastPost.BlogPostID);
        }
        public ActionResult Create(BlogPost blog)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 4
0
        public void SaveBlogPostDbTest()
        {
            var ops = OperationsFactory.CreateBlogPostOps();

            BlogPost blog = new BlogPost()
            {
                DateOfPost = DateTime.Now,
                PostContent = "<p>Hello Lovely</p>",
                PostTitle = "Blog One",
                Status = new Status() { StatusID = 1 }

            };

            ops.SaveBlogPost(blog);
            var list = ops.GetAllBlogPosts();
            Assert.AreEqual(1,list.Count);
        }
Exemplo n.º 5
0
        public void SaveBlogPostDBTest()
        {
            var repo = new BlogPostRepo();
            BlogPost blog = new BlogPost()
            {
               PostContent = "<p>Hello Everyone</p>",
               PostTitle = "Blog More",
               Status = new Status(){StatusID = 1},
               //UserID = "f319beb5-8a14-40c1-9cb5-0d6c92571ae4",
               DateOfPost = DateTime.Now

            };
            repo.SaveBlogPost(blog);
            var list = repo.GetAllBlogPosts();
            Assert.AreEqual(6,list.Count);
            Assert.AreEqual("Blog One", list.FirstOrDefault(x=>x.BlogPostID == 1).PostTitle);
        }
Exemplo n.º 6
0
        public void EditBlogPost(BlogPost blog)
        {
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand(
                    "UPDATE [dbo].[BlogPost]" +
                    "SET [PostContent] = @PostContent," +
                    "[StatusID] = @StatusId," +
                    "[DateOfPost] = @DateOfPost," +
                    "[PostTitle] = @PostTitle" +
                    "WHERE [BlogPostID] = @BlogPostId)");
                cmd.Parameters.AddWithValue("@PostContent", blog.PostContent);
                cmd.Parameters.AddWithValue("@StatusId", blog.Status);
                cmd.Parameters.AddWithValue("@DateOfPost", blog.DateOfPost);
                cmd.Parameters.AddWithValue("@PostTitle", blog.PostTitle);

                cn.Open();
                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 7
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;
        }
        public ActionResult Edit(int id, EditPostVM model)
        {
            try
            {
                var blogPost = new BlogPost();

                blogPost = model.EditPost;
                blogPost.BlogPostID = id;
                blogPost.PostContent = model.HtmlContent;
                if (model.EditPost.Status == null)
                {
                    blogPost.Status = new Status()
                    {
                        StatusID = 1

                    };
                }
                else
                {
                    blogPost.Status.StatusID = model.EditPost.Status.StatusID;
                }
                var ops = OperationsFactory.CreateBlogPostOps();
                var categoryOps = OperationsFactory.CreateCategoryOps();
                ops.SaveBlogPost(blogPost);
                categoryOps.SaveBlogPostCategory(model.SelectedCategoryIds, blogPost);

                return RedirectToAction("Index", "ContentManager");
            }
            catch
            {
                return RedirectToAction("Index", "ContentManager");
            }
        }
        public ActionResult Edit(int id, BlogPost blog)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 10
0
        public void SaveBlogPost(BlogPost blog)
        {
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var p = new DynamicParameters();
                p.Add("@UserId", blog.User.UserId);
                p.Add("@PostContent", blog.PostContent);
                p.Add("@StatusID", blog.Status.StatusID);
                p.Add("@DateOfPost", blog.DateOfPost);
                p.Add("@PostTittle", blog.PostTitle);

                if (blog.BlogPostID > 0)
                {
                    p.Add("@BlogPostId", blog.BlogPostID);

                    cn.Execute("UpdateBlogPost", p, commandType: CommandType.StoredProcedure);
                }
                else
                {
                    cn.Query("SubmitNewBlogPost", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
Exemplo n.º 11
0
 public void SaveBlogPost(BlogPost blog)
 {
 }
Exemplo n.º 12
0
        public BlogPost GetBlogPostById(int blogPostId)
        {
            //var singleBlogPost = new BlogPost();
            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;
            //}

            //singleBlogPost = blogPosts.FirstOrDefault(bp => bp.BlogPostID == blogPostId);

            //return singleBlogPost;
            return null;
        }
Exemplo n.º 13
0
        public BlogPost GetBlogPostById(int blogPostId)
        {
            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 where b.BlogPostID = BlogPostID 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);

                        return blog;
                    }
                }

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

            return null;
        }
Exemplo n.º 14
0
 public void SaveBlogPost(BlogPost blog)
 {
     if (blog.DateOfPost > new DateTime(01 / 01 / 2000))
         _repo.SaveBlogPost(blog);
 }
Exemplo n.º 15
0
 public void EditBlogPost(BlogPost blog)
 {
     _repo.EditBlogPost(blog);
 }
Exemplo n.º 16
0
        public List<BlogPost> ListAllBlogsInCategoryByCategoryId(int categoryId)
        {
            var blogPosts = new List<BlogPost>();
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand("select bp.UserID, bp.PostContent,bp.StatusID, s.StatusType,bp.DateOfPost,bp.PostTitle,bp.BlogPostID,u.UserName, u.FirstName,u.LastName from BlogPost bp inner join PostCategories pc on bp.BlogPostID = pc.BlogPostID inner join CategoryOfPost cp  on cp.CategoryID = pc.CategoryID inner join AspNetUsers u on u.Id = bp.UserID inner join [Status] s on s.StatusID = bp.StatusID where pc.CategoryID =@catId order by bp.DateOfPost desc", cn);
                cmd.Parameters.AddWithValue("@catId", categoryId);
                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);
                        blog.User.UserName = dr.GetString(7);
                        blog.User.FirstName = dr.GetString(8);
                        blog.User.LastName = dr.GetString(9);

                        blogPosts.Add(blog);
                    }
                }

            }
            return blogPosts;
        }
Exemplo n.º 17
0
 public void EditBlogPost(BlogPost blog)
 {
     throw new NotImplementedException();
 }