示例#1
0
        public IHttpActionResult GetSwntByCriteria([FromBody] SwntDataFilter criteria)
        {
            var source = (dynamic)null;

            try
            {
                SortingPagingInfo sortingPagingInfo = new SortingPagingInfo();
                sortingPagingInfo.SortField        = criteria.SortField;
                sortingPagingInfo.SortDirection    = criteria.SortDirection;
                sortingPagingInfo.PageSize         = criteria.PageSize;
                sortingPagingInfo.CurrentPageIndex = criteria.PageNo;
                UprdSwntRepository uprdSwntRepository = new UprdSwntRepository();

                if (!string.IsNullOrEmpty(criteria.PipelineDuns))
                {
                    source = uprdSwntRepository.GetSwntListWithPaging(criteria.PipelineDuns, criteria.IsCritical, criteria.Keyword, criteria.postStartDate, criteria.postEndDate, criteria.EffectiveStartDate, criteria.EffectiveEndDate, sortingPagingInfo);
                    int count       = sortingPagingInfo.PageCount;
                    int CurrentPage = sortingPagingInfo.CurrentPageIndex;
                    int PageSize    = sortingPagingInfo.PageSize;
                    int TotalCount  = count;

                    int TotalPages = (int)Math.Ceiling(count / (double)PageSize);

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

                    // if TotalPages is greater than CurrentPage means it has nextPage
                    var nextPage = CurrentPage < TotalPages ? "Yes" : "No";

                    // Object which we are going to send in header
                    var paginationMetadata = new
                    {
                        totalCount  = TotalCount,
                        pageSize    = PageSize,
                        currentPage = CurrentPage,
                        totalPages  = TotalPages,
                        previousPage,
                        nextPage
                    };

                    // Setting Header
                    HttpContext.Current.Response.Headers.Add("Paging-Headers", JsonConvert.SerializeObject(paginationMetadata));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error in notice controller in API.", ex);
            }
            if (source == null)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    //Content = new StringContent(string.Format("No product with ID = {0}", id)),
                    ReasonPhrase = "Records Not Found."
                };
                throw new HttpResponseException(resp);
            }

            return(Ok(source));
        }
示例#2
0
        public IHttpActionResult GetSwntTotalRecords([FromBody] SwntDataFilter criteria)
        {
            UprdSwntRepository uprdSwntRepository = new UprdSwntRepository();
            int records = uprdSwntRepository.GetSwntListTotalCount(criteria.PipelineDuns, criteria.IsCritical, criteria.Keyword, criteria.postStartDate, criteria.postEndDate, criteria.EffectiveStartDate, criteria.EffectiveEndDate);

            return(Ok(records));
        }