Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
        public IHttpActionResult GetNoticeOnId(int id)
        {
            UprdSwntRepository uprdSwntRepository = new UprdSwntRepository();
            var notice = uprdSwntRepository.GetNoticeById(id);

            if (notice != null)
            {
                return(Ok(notice));
            }
            return(NotFound());
        }
Exemplo n.º 4
0
        public IHttpActionResult FilterNotices(string PipelineDuns, bool isCritical, DateTime startDate, DateTime endDate)
        {
            UprdSwntRepository uprdSwntRepository = new UprdSwntRepository();
            var result = uprdSwntRepository.GetByCreatedDateRange(PipelineDuns, isCritical, startDate, endDate);

            List <BONotice> noticeList = new List <BONotice>();

            foreach (var item in result)
            {
                BONotice notice = uprdSwntRepository.MappingNotice(item);
                noticeList.Add(notice);
            }
            return(Json(noticeList));
        }