public async Task <int> GetAdminUnreadCountAsync() { if (HasPermission(Permission.ReadAllMail)) { int siteId = GetClaimId(ClaimType.SiteId); var cacheKey = UnhandledMailCount(siteId); var cacheUnhandledCount = await _cache.GetIntFromCacheAsync(cacheKey); if (!cacheUnhandledCount.HasValue) { int unhandledCount = await _mailRepository.GetAdminUnrepliedCountAsync(siteId); await _cache.SaveToCacheAsync(cacheKey, unhandledCount, ExpireInTimeSpan()); return(unhandledCount); } else { return(cacheUnhandledCount.Value); } } else { var userId = GetClaimId(ClaimType.UserId); _logger.LogError($"User {userId} doesn't have permission to get unread mail count."); throw new GraException("Permission denied."); } }
public async Task <DataWithCount <IEnumerable <Mail> > > GetAllUnrepliedPaginatedAsync(int skip, int take) { if (HasPermission(Permission.ReadAllMail)) { int siteId = GetClaimId(ClaimType.SiteId); return(new DataWithCount <IEnumerable <Mail> > { Data = await _mailRepository.PageAdminUnrepliedAsync(siteId, skip, take), Count = await _mailRepository.GetAdminUnrepliedCountAsync(siteId) }); } else { var userId = GetClaimId(ClaimType.UserId); _logger.LogError($"User {userId} doesn't have permission to get all unread mails."); throw new GraException("Permission denied."); } }