예제 #1
0
        private string CreatePageLink(UserTaskPage taskPage, GetUserTasksParameters parameters, int offset)
        {
            if (offset > 0 && !taskPage.HasNextPage)
            {
                return(null);
            }

            if (offset < 0 && !taskPage.HasPreviousPage)
            {
                return(null);
            }

            var routeValues = new
            {
                PageSize   = taskPage.PageSize,
                PageNumber = taskPage.CurrentPage + offset,
                parameters.SearchQuery,
                parameters.GroupName,
                parameters.Overdue,
                parameters.CreatedBy,
                parameters.AssignedTo
            };

            string link = _urlHelper.Link(nameof(GetAllUserTasks), routeValues);

            return(link);
        }
예제 #2
0
        public async Task <IActionResult> GetAllUserTasks(GetUserTasksParameters parameters)
        {
            if (parameters == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(UnprocessableEntity(ModelState));
            }

            User loggedOnUser = await _identityBusiness.GetUserAsync(User);

            UserTaskPage taskPage = await _taskBookBusiness.GetUsersTaskByUserId(loggedOnUser.Id, parameters);

            string previousPageLink = CreatePageLink(taskPage, parameters, -1);
            string nextPageLink     = CreatePageLink(taskPage, parameters, 1);

            var metaData = new
            {
                taskPage.TotalCount,
                taskPage.PageSize,
                taskPage.TotalPages,
                taskPage.CurrentPage,
                previousPageLink,
                nextPageLink
            };

            string pagingMetaDataJson = JsonConvert.SerializeObject(metaData);

            Response.Headers.Add("X-PagingMetadata", pagingMetaDataJson);

            var models = _mapper.Map <TaskViewModel[]>(taskPage.Tasks);

            return(Ok(models));
        }