public async Task <Mail> SendSystemMailAsync(Mail mail, int?siteId = null) { var user = await _userRepository.GetByIdAsync(mail.ToUserId.Value); if (user != null) { mail.FromUserId = 0; mail.IsNew = true; mail.IsDeleted = false; mail.CreatedAt = _dateTimeProvider.Now; mail.SiteId = siteId ?? GetClaimId(ClaimType.SiteId); _cache.Remove(UnreadMailCacheKey(mail.SiteId, (int)mail.ToUserId)); return(await _mailRepository.AddSaveNoAuditAsync(mail)); } else { throw new GraException("User doesn't exist"); } }
public async Task <Mail> SendSystemMailAsync(Mail mail) { var user = await _userRepository.GetByIdAsync(mail.ToUserId.Value); if (user != null) { mail.FromUserId = 0; mail.IsNew = true; mail.IsDeleted = false; mail.CreatedAt = DateTime.Now; mail.SiteId = GetClaimId(ClaimType.SiteId); _memoryCache.Remove($"{CacheKey.UserUnreadMailCount}?u{mail.ToUserId}"); return(await _mailRepository.AddSaveNoAuditAsync(mail)); } else { throw new GraException("User doesn't exist"); } }