Example #1
0
        public async Task <IActionResult> GetAllHome([FromQuery(Name = "pageNumber")] int PageNumber, [FromQuery(Name = "pageSize")] int PageSize)
        {
            try
            {
                if (PageNumber <= 0)
                {
                    return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, "Page number not found!"));
                }
                else if (PageSize <= 0)
                {
                    return(StatusCode((int)System.Net.HttpStatusCode.BadRequest, "Page size not found!"));
                }
                else
                {
                    PagedList <HomeContentDTO> items = await _homeRepo.GetAllHomeContents(PageNumber, PageSize);

                    if (items != null)
                    {
                        var result = new
                        {
                            items.TotalCount,
                            items.PageSize,
                            items.CurrentPage,
                            items.TotalPages,
                            items.HasNext,
                            items.HasPrevious,
                            items
                        };
                        return(Ok(result));
                    }
                    else
                    {
                        return(NoContent());
                    }
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError, ex.Message));
            }
        }