Esempio n. 1
0
        public PostsResponse Edit(Post post)
        {
            var context  = new PersonalBlogEntities();
            var response = new PostsResponse();

            if (string.IsNullOrEmpty(post.PostTitle))
            {
                response.Success = false;
                response.Message = "The post title cannot be left blank.";
            }
            else if (!post.IsApproved)
            {
                response.Success = false;
                response.Message = "This post has content that violates our blogging policy.";
            }
            else if (string.IsNullOrEmpty(post.PostBody))
            {
                response.Success = false;
                response.Message = "The post body cannot be left blank.";
            }
            else if (context.Categories.FirstOrDefault(c => c.CategoryId == post.CategoryId) == null)
            {
                response.Success = false;
                response.Message = "That category is invalid";
            }
            else
            {
                response         = repo.Edit(post);
                response.Message = $"Your changes to \"{post.PostTitle}\" have been saved.";
            }

            return(response);
        }
Esempio n. 2
0
        public void EditPost()
        {
            Post test = repo.GetByCategory(1).Posts.First();

            test.PostTitle = "HurrMurmuhFur";

            PostsResponse response = repo.Edit(test);
            Post          edited   = repo.GetByCategory(1).Posts.First();

            Assert.AreEqual(true, response.Success);
            Assert.AreEqual("HurrMurmuhFur", edited.PostTitle);
        }