Exemplo n.º 1
0
        public void GetAll()
        {
            TagsResponse actual = _repo.GetAll();

            Assert.AreEqual(true, actual.Success);
            Assert.AreEqual("#MeToo", actual.Tags.Where(t => t.TagId == 1));
            Assert.AreEqual("#Neature", actual.Tags.Where(t => t.TagId == 3));
        }
Exemplo n.º 2
0
        public void GetAll()
        {
            TagsResponse response = repo.GetAll();
            Tag          actual   = response.Tags.Where(t => t.TagId == 3).First();

            Assert.AreEqual(true, response.Success);
            Assert.AreEqual("#Neature", actual.TagName);
        }
Exemplo n.º 3
0
        public PostsResponse Add(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.CreatedDate < DateTime.Today.AddDays(1))
            {
                response.Success = false;
                response.Message = "The post cannot have a creation date before the current date.";
            }
            //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
            {
                TagsRepo tagsRepo = new TagsRepo();

                List <Tag> allTags   = tagsRepo.GetAll().Tags.ToList();
                List <Tag> tagsToAdd = post.Tags.AsEnumerable().Where(t => post.Tags.Any(postTag => postTag.TagName != t.TagName)).ToList();
                foreach (Tag t in tagsToAdd)
                {
                    tagsRepo.Add(t);
                }
                response         = repo.Add(post);
                response.Message = $"The post \"{post.PostTitle}\" has been added to the database.";
            }

            return(response);
        }
Exemplo n.º 4
0
 public TagsResponse GetAll()
 {
     return(repo.GetAll());
 }