Exemplo n.º 1
0
        public Post UpdatePost(int? id, string title, string body, DateTime date, string tags, string photoPath)
        {
            BlogRepository _repo = new BlogRepository();
            TagBLL tagBLL = new TagBLL();

            Post post = _repo.GetPost(id);

            post.Title = title;
            post.Body = body;

            post.Preview = body.BlogPreviewTruncate();

            post.Date = date;
            post.PhotoPath = photoPath;
            post.DateEdited = DateTime.Now;

            string newTitle = UrlTitleWithDashes(title);
            newTitle = SanitizedUrlTitle(newTitle);
            post.UrlTitle = newTitle;

            post.Tags.Clear();
            post.Tags = tagBLL.CreateTag(tags);

            List<string> tagList = post.Tags.Select(x => x.Name).ToList();

            if (tagList.Count != 0)
            {
                if (post.Views == 0)
                {
                    int tagSuccess = _repo.IncrementTags(tagList);
                }

            }

            if (post.Views > 0)
            {
                //Stupid logic, should have a different method for UpdatePost and NewPost...ugh.
                post.Views--;
            }

            bool success = _repo.SavePost(post);

            return success ? post : null;
        }
Exemplo n.º 2
0
        public void TagListCreatedSuccessfully()
        {
            string tags = "visual studio c# hello world";

            TagBLL tagBLL = new TagBLL();

            List<Tag> sut = tagBLL.CreateTag(tags);

            Tag tag1 = new Tag {Name = "visual"};
            Tag tag2 = new Tag { Name = "studio" };
            Tag tag3 = new Tag { Name = "c#" };
            Tag tag4 = new Tag { Name = "hello" };
            Tag tag5 = new Tag { Name = "world" };

            Assert.That(tag1.Name, Is.EqualTo(sut[0].Name));
            Assert.That(tag2.Name, Is.EqualTo(sut[1].Name));
            Assert.That(tag3.Name, Is.EqualTo(sut[2].Name));
            Assert.That(tag4.Name, Is.EqualTo(sut[3].Name));
            Assert.That(tag5.Name, Is.EqualTo(sut[4].Name));

            Assert.That(sut.Count, Is.EqualTo(5));
        }