Ejemplo n.º 1
0
        /// <summary>
        /// The method returns the view with list of all topics and adds a pagination
        /// </summary>
        public ActionResult GetAllTopics(int page = 1)
        {
            IEnumerable <TopicDTO> topicDTOs = topicService.GetAllElements();

            Mapper.Initialize(configuration => configuration.CreateMap <TopicDTO, TopicModel>());
            var allTopics = Mapper.Map <IEnumerable <TopicDTO>, List <TopicModel> >(topicDTOs);

            PaginationTopicsModel topicsWithPagination = CreatePaginationForTopics(allTopics, page);

            return(View("AllTopics", topicsWithPagination));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The method shows all news with short-description in the blog
        /// </summary>
        /// <returns>The views with list of news</returns>
        public ActionResult Index(int page = 1)
        {
            IEnumerable <TopicDTO> topicDTOs = topicService.GetAllElements();

            topicDTOs.ToList().ForEach(topic => topic.Description = topic.Description.Substring(0, 100));

            Mapper.Initialize(configuration => configuration.CreateMap <TopicDTO, TopicModel>());
            var topicsForDisplay = Mapper.Map <IEnumerable <TopicDTO>, List <TopicModel> >(topicDTOs);

            PaginationTopicsModel topicsWithPagination = CreatePaginationForTopics(topicsForDisplay, page);

            return(View("Index", topicsWithPagination));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The method adds the pagination for collection of topics
        /// </summary>
        /// <param name="products">The list of topics without pagination</param>
        /// <param name="page">The number of current page</param>
        private PaginationTopicsModel CreatePaginationForTopics(IEnumerable <TopicModel> topics, int page)
        {
            int amountOfItemOnPage = 10;
            IEnumerable <TopicModel> topicsOnPage = topics.Skip((page - 1) * amountOfItemOnPage).Take(amountOfItemOnPage);

            PageModel pageModel = new PageModel
            {
                PageNumber   = page,
                PageCapacity = amountOfItemOnPage,
                TotalItems   = topics.Count()
            };

            PaginationTopicsModel topicsOnPages = new PaginationTopicsModel
            {
                Page   = pageModel,
                Topics = topicsOnPage
            };

            return(topicsOnPages);
        }