Example #1
0
        public async Task <IActionResult> GetAll([FromQuery] PaginationParameters parameters)
        {
            int userId = int.Parse(HttpContext.Items["UserId"].ToString());
            PagedList <ToDoItemDto> pagedToDoItemDto = await _itemService.GetAllByUser(parameters, userId);

            if (pagedToDoItemDto != null)
            {
                if (pagedToDoItemDto.Count > 0)
                {
                    var metadata = new
                    {
                        pagedToDoItemDto.TotalCount,
                        pagedToDoItemDto.PageSize,
                        pagedToDoItemDto.CurrentPage,
                        pagedToDoItemDto.TotalPages,
                        pagedToDoItemDto.HasNext,
                        pagedToDoItemDto.HasPrevious
                    };
                    Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));
                    return(Ok(
                               new ResponseModel <PagedList <ToDoItemDto> >
                    {
                        IsSuccess = true,
                        Result = pagedToDoItemDto,
                        Message = "Data retrieval successful."
                    }));
                }
                else
                {
                    return(Ok(
                               new ResponseModel <string>
                    {
                        IsSuccess = false,
                        Result = "No ToDoItem records present.",
                        Message = " Please add ToDoItems first."
                    }));
                }
            }
            return(NotFound(
                       new ResponseModel <string>
            {
                IsSuccess = false,
                Result = "No Results Found.",
                Message = "No data exist. Please add todo items first."
            }));
        }
        public async Task GetAllTest()
        {
            PagedList <ToDoItemDto> result = await _ToDoItemService.GetAllByUser(paginationParameters, 1);

            Assert.IsNotNull(result);
        }