コード例 #1
0
        public int AddNewBlogPost(BlogPost newBlogPost)
        {
            var p = new DynamicParameters();
            p.Add("CategoryID", newBlogPost.CategoryID);
            p.Add("PostTitle", newBlogPost.PostTitle);
            p.Add("PostDate", newBlogPost.PostDate);
            p.Add("PostContent", newBlogPost.PostContent);
            p.Add("Author", newBlogPost.Author);
            p.Add("PostStatus", newBlogPost.PostStatus);
            p.Add("IsStickyPost", newBlogPost.IsStickyPost);
            p.Add("PublishDate", newBlogPost.PublishDate);
            p.Add("ExpirationDate", newBlogPost.ExpirationDate);
            p.Add("PostID", dbType: DbType.Int32, direction: ParameterDirection.Output);

            _cn.Execute("AddNewPost", p, commandType: CommandType.StoredProcedure);
            return p.Get<int>("PostID");
        }
コード例 #2
0
ファイル: BlogsController.cs プロジェクト: r0cco/BlogProject
        public ActionResult AddBlogPost(BlogPost blogPost)
        {
            var ops = new BlogPostOperations();
            if (User.IsInRole("Admin"))
            {
                // Admin add post, post goes to table with status of 1
                ops.AddNewBlogPost(blogPost);
                return RedirectToAction("Index", "Home");
            }
            if (User.IsInRole("PR"))
            {
                // PR add post, post goes to table with status of 0
                ops.PRAddNewBlogPost(blogPost);
                return RedirectToAction("Index", "Home");
            }

            // somehow a non-authenticated add. nothing goes to data. (necessary?)
            return RedirectToAction("Index", "Home");
        }
コード例 #3
0
        public void AddNewBlogPost(BlogPost newBlogPost)
        {
            newBlogPost.PostDate = DateTime.Now;
            newBlogPost.PostStatus = 1;
            if (newBlogPost.PublishDate == null)
            {
                newBlogPost.PublishDate = DateTime.Now;
            }
            var postId = _repo.AddNewBlogPost(newBlogPost);
            var tagList = _repo.GetAllTags();

            if (newBlogPost.tags != null)
            {
                foreach (var tag in newBlogPost.tags)
                {
                    var tagExists = false;
                    var tagId = 0;

                    foreach (var tag2 in tagList)
                    {
                        if (tag2.TagName == tag)
                        {
                            // Tag already exists, bool set to true
                            tagExists = true;
                            tagId = tag2.TagID;
                            break;
                        }
                    }
                    // Check bool to see if tag exists
                    if (tagExists)
                    {
                        // Tag exists on table, only need to add it to PostTags to tie it to a post
                        _repo.AddNewPostTag(tagId, postId);
                    }
                    else
                    {
                        // Tag doesn't exist on table, needs to be created, then tied to a post on PostTags table
                        tagId = _repo.AddNewTag(tag);
                        _repo.AddNewPostTag(tagId, postId);
                    }
                }
            }
        }
コード例 #4
0
ファイル: BlogsController.cs プロジェクト: r0cco/BlogProject
        public ActionResult EditPost(BlogPost editedPost)
        {
            var ops = new BlogPostOperations();
            ops.EditPost(editedPost);

            return RedirectToAction("Index", "Home");
        }
コード例 #5
0
        public void EditPost(BlogPost postToEdit)
        {
            _repo.EditBlogPost(postToEdit);
            var tagList = _repo.GetAllTags();

            // dissociate tags from old post (in cross table)
            _repo.RemovePostFromPostTagsTable(postToEdit.PostID);

            // add new tags to tags table, then set up new poststags table association (just like in add post)
            if (postToEdit.tags != null)
            {
                foreach (var tag in postToEdit.tags)
                {
                    var tagExists = false;
                    var tagId = 0;

                    foreach (var tag2 in tagList)
                    {
                        if (tag2.TagName == tag)
                        {
                            // Tag already exists, bool set to true
                            tagExists = true;
                            tagId = tag2.TagID;
                            break;
                        }
                    }
                    // Check bool to see if tag exists
                    if (tagExists)
                    {
                        // Tag exists on table, only need to add it to PostTags to tie it to a post
                        _repo.AddNewPostTag(tagId, postToEdit.PostID);
                    }
                    else
                    {
                        // Tag doesn't exist on table, needs to be created, then tied to a post on PostTags table
                        tagId = _repo.AddNewTag(tag);
                        _repo.AddNewPostTag(tagId, postToEdit.PostID);
                    }
                }
            }
        }
コード例 #6
0
        public void EditBlogPost(BlogPost editedPost)
        {
            // Different stored procedures for updating each field. This way it retains the same PostID

            var p = new DynamicParameters();
            p.Add("postId", editedPost.PostID);
            p.Add("newCategoryId", editedPost.CategoryID);
            _cn.Execute("UpdateCategoryID", p, commandType: CommandType.StoredProcedure);

            var p2 = new DynamicParameters();
            p2.Add("postId", editedPost.PostID);
            p2.Add("newPostTitle", editedPost.PostTitle);
            _cn.Execute("UpdatePostTitle", p2, commandType: CommandType.StoredProcedure);

            //p.Add("newPostDate", editedPost.PostDate); no option to edit date yet

            var p3 = new DynamicParameters();
            p3.Add("postId", editedPost.PostID);
            p3.Add("newPostContent", editedPost.PostContent);
            _cn.Execute("UpdatePostContent", p3, commandType: CommandType.StoredProcedure);

            //p.Add("newAuthor", editedPost.Author); no option to change author yet
            //p.Add(newIsStickyPost, editedPost.IsStickyPost); no option to edit IsStickyPost yet

            var p5 = new DynamicParameters();
            p5.Add("postId", editedPost.PostID);
            p5.Add("newIsStickyPost", editedPost.IsStickyPost);
            _cn.Execute("UpdateIsStickyPost", p5, commandType: CommandType.StoredProcedure);

            var p6 = new DynamicParameters();
            p6.Add("postId", editedPost.PostID);
            p6.Add("newPublishDate", editedPost.PublishDate);
            _cn.Execute("UpdatePublishDate", p6, commandType: CommandType.StoredProcedure);

            var p7 = new DynamicParameters();
            p7.Add("postId", editedPost.PostID);
            p7.Add("newExpirationDate", editedPost.ExpirationDate);
            _cn.Execute("UpdateExpirationDate", p7, commandType: CommandType.StoredProcedure);
        }