Beispiel #1
0
        public async Task <IActionResult> GetCurrentUserPurchases(PaginationParameters paging)
        {
            try
            {
                if (paging.PageNumber <= 0)
                {
                    return(BadRequest("page number must larger then 0"));
                }

                var user = await _userServices.GetCurrentUserAsync();

                if (user == null)
                {
                    return(NotFound("user not found"));
                }

                var results = await _courseServices.GetPagedPurchasedCoursesByUserIdAsync(user.Id, paging.PageNumber, paging.PageSize);

                if (!results.Items.Any())
                {
                    return(NotFound("study record not found"));
                }

                var paginationMetadata = GeneratePaginationMetadata(results.TotalCount, results.TotalPages, results.PageSize, results.CurrentPage);
                Response.Headers.Add("X-Pagination", paginationMetadata);
                Response.Headers.Add("Access-Control-Expose-Headers", "X-Pagination");

                return(Ok(results.Items));
            }
            catch (NotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"GetCourses() Error: {ex}");
                return(StatusCode(500, "Internal Server Error"));
            }
        }