public PagedList <UserNotification> GetNotifications(NotificationQueryFilter filters) { filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber; filters.PageSize = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize; var notifications = _unitOfWork.NotificationRepository.GetAll(); if (filters.UserId != null) { notifications = notifications.Where(x => x.UserId == filters.UserId); } if (filters.Time != null) { notifications = notifications.Where(x => x.Time == filters.Time); } var pagedNotifications = PagedList <UserNotification> .Create(notifications, filters.PageNumber, filters.PageSize); return(pagedNotifications); }
public IActionResult GetNotifications([FromQuery] NotificationQueryFilter filters) { var notifications = _notificationService.GetNotifications(filters); var notificationsDto = _mapper.Map <IEnumerable <UserNotificationDto> >(notifications); var metadata = new Metadata { TotalCount = notifications.TotalCount, PageSize = notifications.PageSize, CurrentPage = notifications.CurrentPage, TotalPages = notifications.TotalPages, HasNextPage = notifications.HasNextPage, HasPreviousPage = notifications.HasPreviousPage, }; var response = new ApiResponse <IEnumerable <UserNotificationDto> >(notificationsDto) { Meta = metadata }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); return(Ok(response)); }