コード例 #1
0
        public ActionResult Edit(Post post)
        {
            post.Body = HttpUtility.HtmlDecode(post.Body);
            RepositoryFactory.PostRepository.UpdatePost(post);

            return RedirectToAction("Index", "Home", null);
        }
コード例 #2
0
        public ActionResult Create(Post post, int categoryList)
        {
            post.Body = HttpUtility.HtmlDecode(post.Body);
            post.CategoryID = categoryList;
            RepositoryFactory.PostRepository.CreatePost(post);

            return RedirectToAction("Index", "Home", null);
        }
コード例 #3
0
        public void VerifyPostProperties()
        {
            Post post = new Post
            {
                ID = 1,
                CategoryID = 1,
                Subject = "Subject",
                Body = "Body",
                CreatedBy = 1,
                CreatedOn = DateTime.Now,
                ModifiedBy = 1,
                ModifiedOn = DateTime.Now
            };

            Assert.IsNotNull(post);
        }
コード例 #4
0
        public Post GetPostByID(int id)
        {
            const string sqlQuery = "SELECT ID, CategoryID, Subject, Body, CreatedOn, CreatedBy, ModifiedOn, ModifiedBy " +
                                    "FROM Post " +
                                    "WHERE ID = @id";

            Post post = new Post();

            using (var reader = DbUtil.ExecuteReader(sqlQuery, new SQLiteParameter("@id", id)))
            {
                if (reader.Read())
                {
                    post = ReadPost(reader);
                }
            }

            return post;
        }
コード例 #5
0
        public void UpdatePost(Post post)
        {
            const string sqlQuery = "UPDATE Post " +
                                    "SET CategoryID = @categoryID, " +
                                    "Subject = @subject, " +
                                    "Body = @body, " +
                                    "ModifiedOn = @modifiedOn, " +
                                    "ModifiedBy = @modifiedBy " +
                                    "WHERE ID = @id";
            List<SQLiteParameter> parameters = new List<SQLiteParameter>
            {
                new SQLiteParameter("@categoryID", post.CategoryID),
                new SQLiteParameter("@subject", post.Subject),
                new SQLiteParameter("@body", post.Body),
                new SQLiteParameter("modifiedOn", DateTime.Now),
                new SQLiteParameter("modifiedBy", post.ModifiedBy),
                new SQLiteParameter("@id", post.ID)
            };

            DbUtil.ExecuteNonQuery(sqlQuery, parameters.ToArray());
        }
コード例 #6
0
        public void CreatePost(Post post)
        {
            const string sqlQuery = "INSERT INTO Post(CategoryID, Subject, Body, CreatedOn, CreatedBy, ModifiedOn, ModifiedBy) " + 
                "VALUES (@categoryID, @subject, @body, @createdOn, @createdBy, @modifiedOn, @modifiedBy)";

            // Default to Admin if we don't have a user.
            if (post.CreatedBy == 0)
            {
                post.CreatedBy = 1;
            }

            List<SQLiteParameter> parameters = new List<SQLiteParameter>
            {
                new SQLiteParameter("@categoryID", post.CategoryID),
                new SQLiteParameter("@subject", post.Subject),
                new SQLiteParameter("@body", post.Body),
                new SQLiteParameter("createdOn", DateTime.Now),
                new SQLiteParameter("createdBy", post.CreatedBy),
                new SQLiteParameter("modifiedOn", DateTime.Now),
                new SQLiteParameter("modifiedBy", post.CreatedBy)
            };

            DbUtil.ExecuteNonQuery(sqlQuery, parameters.ToArray());
        }
コード例 #7
0
        public ActionResult Delete(Post post)
        {
            RepositoryFactory.PostRepository.DeletePostByID(post.ID);

            return RedirectToAction("Index", "Home", null);
        }
コード例 #8
0
 public void CreatePost(Post post)
 {
     return;
 }
コード例 #9
0
 public void UpdatePost(Post post)
 {
     return;
 }