Beispiel #1
0
        public ActionResult Post(int postId)
        {
            Post currentPost = postService.GetPost(postId);

            if (currentPost == null)
            {
                string url = "test";
                if (Url != null) // при юнит-тестирование будет равняться null
                {
                    url = Url.Home();
                }

                return(Redirect(url));
            }

            PostPagingInfo pagingInfo = postService.GetPostPagingInfo(postId);

            HomePostViewModel model = new HomePostViewModel
            {
                PagingInfo = pagingInfo,
                Post       = currentPost
            };

            TempData["fullpost"] = 1;
            return(View(model));
        }
Beispiel #2
0
        public PostPagingInfo GetPostPagingInfo(int postId)
        {
            PostPagingInfo pagingInfo = new PostPagingInfo();

            Post previous = repository.Posts.Where(x => x.PostId < postId).OrderByDescending(x => x.PostId).FirstOrDefault();
            Post next     = repository.Posts.Where(x => x.PostId > postId).OrderBy(x => x.PostId).FirstOrDefault();

            pagingInfo.Previous = previous;
            pagingInfo.Next     = next;

            return(pagingInfo);
        }
        public void Can_Send_PostPagination_View_Model_3()
        {
            // Arrange
            IPostRepository repository = MockPostRepository.GetRepository(MockPostRepository.STDN);
            IPostService    service    = new PostService(repository);
            HomeController  target     = new HomeController(service);

            // Act
            PostPagingInfo pagingInfo = ((HomePostViewModel)((ViewResult)target.Post(MockPostRepository.STDN)).Model).PagingInfo;

            // Assert

            Assert.IsTrue(pagingInfo.Previous.PostId == MockPostRepository.STDN - 1);
            Assert.IsNull(pagingInfo.Next);
        }
Beispiel #4
0
        public static MvcHtmlString PageLinks(this HtmlHelper html, PostPagingInfo pagingInfo, Func <int, string> pageUrl)
        {
            StringBuilder result = new StringBuilder();

            for (int i = 1; i <= pagingInfo.TotalPages; i++)
            {
                TagBuilder tag = new TagBuilder("a");
                tag.MergeAttribute("href", pageUrl(i));
                tag.InnerHtml = i.ToString();
                if (i == pagingInfo.CurrentPage)
                {
                    tag.AddCssClass("selected");
                    tag.AddCssClass("btn-primary");
                }
                tag.AddCssClass("btn btn-default");
                result.Append(tag.ToString());
            }

            return(MvcHtmlString.Create(result.ToString()));
        }