Exemple #1
0
        public IHttpActionResult GetPosts([FromUri] FlutterPostFilterModel filter, [FromUri] PagingParameterModel paging)
        {
            if (filter == null)
            {
                filter = new FlutterPostFilterModel();
            }

            if (paging == null)
            {
                paging = new PagingParameterModel();
            }

            var pagination = new PaginationMetadataModel()
            {
                currentPage = paging.pageNumber,
                pageSize    = paging.pageSize
            };

            var posts = _service.getPosts(filter, ref pagination);

            // Setting Header
            HttpContext.Current.Response.Headers.Add("Access-Control-Expose-Headers", "X-Paging-Headers");
            HttpContext.Current.Response.Headers.Add("X-Paging-Headers", JsonConvert.SerializeObject(pagination));

            return(Ok <List <FlutterPostCardModel> >(posts));
        }
Exemple #2
0
        public IHttpActionResult GetPolicies([FromUri] PagingParameterModel paging)
        {
            var filter = new FlutterPostFilterModel()
            {
                categorySlug = "chinh-sach"
            };

            return(GetPosts(filter, paging));
        }
        public List <FlutterPostCardModel> getPosts(FlutterPostFilterModel filter, ref PaginationMetadataModel pagination)
        {
            using (var con = new inventorymanagementEntities())
            {
                var posts = con.PostPublics.Where(x => x.IsPolicy == filter.isPolicy);

                if (!String.IsNullOrEmpty(filter.categorySlug))
                {
                    var categories = _postCategory.getPostCategoryChild(filter.categorySlug);

                    if (categories == null || categories.Count() == 0)
                    {
                        return(null);
                    }

                    var categoriesID = categories.Select(x => x.id).ToList();
                    posts = posts.Where(p => categoriesID.Contains(p.CategoryID));
                }

                var data = posts
                           .OrderByDescending(o => o.ModifiedDate)
                           .Select(x => new FlutterPostCardModel()
                {
                    action      = x.Action,
                    name        = x.Title,
                    actionValue = x.Action == FlutterPageNavigation.ViewMore ? (x.IsPolicy ? "policy/" : "post/") + x.ActionValue : x.ActionValue,
                    image       = x.Thumbnail,
                    message     = x.Summary,
                    createdDate = x.ModifiedDate
                })
                           .ToList();

                // Lấy tổng số record sản phẩm
                pagination.totalCount = data.Count();

                // Calculating Totalpage by Dividing (No of Records / Pagesize)
                pagination.totalPages = (int)Math.Ceiling(pagination.totalCount / (double)pagination.pageSize);

                var result = data
                             .Skip((pagination.currentPage - 1) * pagination.pageSize)
                             .Take(pagination.pageSize)
                             .ToList();

                // if CurrentPage is greater than 1 means it has previousPage
                pagination.previousPage = pagination.currentPage > 1 ? "Yes" : "No";

                // if TotalPages is greater than CurrentPage means it has nextPage
                pagination.nextPage = pagination.currentPage < pagination.totalPages ? "Yes" : "No";

                return(result);
            }
        }