Exemplo n.º 1
0
        public async Task <IActionResult> GetAllContacts([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 <ContactUsDTO> items = await _contactRepo.GetCMSContacts(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));
            }
        }