Beispiel #1
0
 public ActionResult DeletePost(Post post)
 {
     //if (ModelState.IsValid)
     {
         var manager = new AdminManager();
         manager.DeletePost(post);
     }
     return RedirectToAction("Index", "Home");
 }
Beispiel #2
0
        public ActionResult EditPost(Post post)
        {
            //if (ModelState.IsValid)
            {
                var manager = new AdminManager();
                post.PostDate = DateTime.Now;
                post.PostCategory.CategoryName = manager.GetCategoryByID(post.PostCategory.CategoryID).CategoryName;
                manager.EditPost(post);

            }
            return RedirectToAction("Index", "Home");
        }
        public ActionResult CreatePost(Post post)
        {
            var manager = new AdminManager();
            var postCount = manager.GetAllPosts().Count;
            post.PostCategory.CategoryName = manager.GetCategoryByID(post.PostCategory.CategoryID).CategoryName;

            post.PostDate = DateTime.Now;
            post.Status = ApprovalStatus.Pending;
            if (postCount == 0)
            {
                post.PostID = 1;
            }
            else
                post.PostID = manager.GetAllPosts().Count + 1;
            manager.AddPost(post);
            return RedirectToAction("SubordinateIndex", "Subordinate");
        }
        public void EditPost(Post post)
        {
            post.User = new User();
            using (SqlConnection cn = new SqlConnection(_connectionString))
            {
                var p = new DynamicParameters();
                p.Add("PostID", post.PostID);
               p.Add("UserID", post.User.UserID);
                p.Add("CategoryID", post.PostCategory.CategoryID);
                p.Add("PostTitle", post.PostTitle);
                p.Add("PostSubTitle", post.PostSubtitle);
                p.Add("PostBody", post.PostBody);
                p.Add("PostStatus", post.Status);
                p.Add("PostDate", post.PostDate.ToShortDateString());

                cn.Execute("UpdateBlogPost", p,
                    commandType: CommandType.StoredProcedure);
            }
        }
Beispiel #5
0
        public void AddPost(Post post)
        {
            var taglist = new List<Tag>();
            var posttags = post.placeholderText;
            if (GetAllPosts().Count != 0)
            {
                post.PostID = GetAllPosts().LastOrDefault().PostID + 1;
            }
            else
            {
                post.PostID = 1;
            }
            if (post.placeholderText != null)
            {
                taglist = _postRepo.AddTagToPost(posttags, post.PostID);
                post.PostTags = taglist;
            }

            post.PostDate = DateTime.Now;

            _postRepo.AddPost(post);
        }
Beispiel #6
0
        public void CanAddPost()
        {
            var manager = new AdminManager();
            var postCount = manager.GetAllPosts().Count;

            var toAdd = new Post();
            toAdd.PostCategory = new Category();

            toAdd.PostID = postCount + 1;
            toAdd.PostTitle = "Test Title";
            toAdd.PostBody = "Post body";
            toAdd.PostCategory.CategoryID = 1;
            toAdd.Status = ApprovalStatus.Approved;
            toAdd.PostDate = DateTime.Now;
            toAdd.PostTags = new List<Tag>();
            toAdd.User = new User();

            manager.AddPost(toAdd);

            var manager2 = new AdminManager();
            var postCount2 = manager2.GetAllPosts().Count;

            Assert.AreEqual(postCount + 1, postCount2);
        }
Beispiel #7
0
        public void EditPost(Post post)
        {
            var taglist = new List<Tag>();
            var posttags = post.placeholderText;
            _tagRepo.DeletePostTagsById(post.PostID);

            if (posttags != null)
            {
                taglist = _postRepo.AddTagToPost(posttags, post.PostID);
            }
            _postRepo.EditPost(post);
        }
Beispiel #8
0
 public void DenyPost(Post post)
 {
     post.Status = ApprovalStatus.Denied;
 }
Beispiel #9
0
 public void DeletePost(Post post)
 {
     _postRepo.DeletePost(post.PostID);
     _tagRepo.DeletePostTagsById(post.PostID);
 }
Beispiel #10
0
 public void ApprovePost(Post post)
 {
     post.Status = ApprovalStatus.Approved;
 }
 public void AddPost(Post post)
 {
     _posts.Add(post);
 }
 public void EditPost(Post post)
 {
     var selectedPost = _posts.FirstOrDefault(p => p.PostID == post.PostID);
     selectedPost.PostID = post.PostID;
     selectedPost.User = post.User;
     selectedPost.PostTitle = post.PostTitle;
     selectedPost.PostBody = post.PostBody;
     selectedPost.PostCategory = post.PostCategory;
     selectedPost.Status = post.Status;
     //selectedPost.PostTags = post.PostTags;
     selectedPost.PostDate = DateTime.Now;
     selectedPost.placeholderText = post.placeholderText;
 }
Beispiel #13
0
 public Post PopulateFromDataReader(SqlDataReader dr)
 {
     string statusCheck;
     Post post  = new Post();
     post.PostCategory = new Category();
     post.PostID = (int) dr["PostID"];
     post.PostTitle = dr["PostTitle"].ToString();
     post.PostCategory.CategoryID = (int) dr["CategoryID"];
     post.PostBody = dr["PostBody"].ToString();
     post.PostDate = (DateTime) dr["PostDate"];
        // post.Status = Enum.Parse(typeof(ApprovalStatus), dr["PostStatus"]);
     statusCheck = dr["PostStatus"].ToString();
     post.Status = (ApprovalStatus)Enum.Parse(typeof(ApprovalStatus), statusCheck);
     return post;
 }
Beispiel #14
0
        public Post GetPostById(int id)
        {
            var tagRepo = new TagRepo();
            var catRepo = new CategoryRepo();
            var post = new Post();

            using (SqlConnection cn = new SqlConnection(_connectionString))
            {

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = @"SELECT * From Post p INNER JOIN Categories c ON p.CategoryID = c.CategoryID WHERE p.PostID ="+id;
                cmd.Connection = cn;
                cn.Open();
                using (var dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                        post = (PopulateFromDataReader(dr));
                }

            }
            // Get Tags for post and populate string placeholder
            post.PostTags = tagRepo.GetTagsByPostId(post.PostID);
            string tags = "";
            foreach (var tag in post.PostTags)
            {
                tags += tag.TagName + ",";
            }
            if (tags.Length > 0)
            {
                post.placeholderText = tags.Substring(0, tags.Length - 1);
            }
            post.PostCategory = catRepo.GetCategoryByID(post.PostCategory.CategoryID);
            return post;
        }