public PagingMetadata GetUsersPagingMetadata() { PagingMetadata metadata = new PagingMetadata(); metadata.TotalCount = this.UnitOfWork.UsersRepository.Query().Count(); return(metadata); }
private ObjectResult ForAdministrator(int page, int pageSize) { var crashReportCount = _mainDbContext.CrashReports .AsNoTracking() .Count(); var crashReports = _mainDbContext.CrashReports .Include(cr => cr.UserCrashReports.Where(ucr => ucr.UserId == -1)) .AsNoTracking() .OrderBy(cr => cr.CreatedAt) .Skip((page - 1) * pageSize) .Take(pageSize) .Select(cr => new CrashReportModel(cr.Id, cr.Exception, cr.CreatedAt, cr.Url) { Status = cr.UserCrashReports.Any() ? cr.UserCrashReports.First().Status : CrashReportStatus.New, Comment = cr.UserCrashReports.Any() ? cr.UserCrashReports.First().Comment : string.Empty }) .ToList(); var metadata = new PagingMetadata { PageSize = pageSize, CurrentPage = page, TotalCount = crashReportCount, TotalPages = (int)Math.Floor((double)crashReportCount / (double)pageSize), }; return(StatusCode((int)HttpStatusCode.OK, new PagingResponse <CrashReportModel> { Items = crashReports, Metadata = metadata })); }
public PagingMetadata GetHaikusForPagingMetadata(string nickname) { PagingMetadata metadata = new PagingMetadata(); metadata.TotalCount = this.UnitOfWork.HaikusRepository .QueryInclude(h => h.User) .Where(h => h.User.Nickname == nickname) .Count(); return(metadata); }
public async Task <ActionResult> GetAll([FromQuery] ModsQuery query) { var page = query.Page; var pageSize = Math.Max(Math.Min(query.PageSize, 20), 5); if (User.IsInRole(ApplicationRoles.Administrator) || User.IsInRole(ApplicationRoles.Moderator)) { return(StatusCode((int)HttpStatusCode.OK, new PagingResponse <ModModel> { Items = new List <ModModel>(), Metadata = new PagingMetadata() })); } if (!HttpContext.User.HasClaim(c => c.Type == "nmapikey") || HttpContext.User.Claims.FirstOrDefault(c => c.Type == "nmapikey") is not { } apiKeyClaim) { return(StatusCode((int)HttpStatusCode.BadRequest, new StandardResponse("Invalid Bearer!"))); } if (await _nexusModsAPIClient.ValidateAPIKey(apiKeyClaim.Value) is not { } validateResponse) { return(StatusCode((int)HttpStatusCode.Unauthorized, new StandardResponse("Invalid NexusMods API Key from Bearer!"))); } var userModCount = _mainDbContext.Mods .AsNoTracking() .Count(m => m.UserIds.Contains(validateResponse.UserId)); var userMods = _mainDbContext.Mods .AsNoTracking() .OrderBy(m => m.ModId) .Where(m => m.UserIds.Contains(validateResponse.UserId)) .Select(m => new ModModel(m.Name, m.GameDomain, m.ModId)) .Skip((page - 1) * pageSize) .Take(pageSize) .ToList(); var metadata = new PagingMetadata { PageSize = pageSize, CurrentPage = page, TotalCount = userModCount, TotalPages = (int)Math.Ceiling((double)userModCount / (double)pageSize), }; return(StatusCode((int)HttpStatusCode.OK, new PagingResponse <ModModel> { Items = userMods, Metadata = metadata })); }
public PagingMetadata GetHaikusPagingMetadata() { PagingMetadata metadata = new PagingMetadata(); metadata.TotalCount = this.unitOfWork.HaikusRepository.Query().Count(); return metadata; }
public void AddHeaders(HttpResponse response, PagingMetadata meta) { response.Headers.Add(HeaderKeys.PageNumber, new StringValues(meta.PageNumber.ToString())); response.Headers.Add(HeaderKeys.PageSize, new StringValues(meta.PageSize.ToString())); response.Headers.Add(HeaderKeys.Total, new StringValues(meta.Total.ToString())); }