public async void CleanExpiredTokenDaily() { _logger.LogInformation($"{DateTime.Now}: Clean expired refresh token started."); var expiredTokens = await _context.RefreshToken.Where(it => it.Expires < DateTime.UtcNow) .ToListAsync(); _logger.LogInformation($"{DateTime.Now}: Find {expiredTokens.Count} token expired."); _context.RemoveRange(expiredTokens); _context.SaveChanges(); _logger.LogInformation($"{DateTime.Now}: Clean expired refresh token finished."); }
public async Task <Collection> DeleteCollection(int userId, int postId) { var item = await _context.Collection.FirstOrDefaultAsync(it => it.UserId == userId && it.PostId == postId); if (item == null) { return(null); } _context.Collection.Remove(item); _context.SaveChanges(); return(item); }
public async Task <string> GetRefreshToken(int userId, string token) { var savedToken = await _context.RefreshToken.FirstOrDefaultAsync(it => it.Token == token && it.User.UserId == userId); if (savedToken == null) { return(null); } if (savedToken.Expires < DateTime.UtcNow) { _context.RefreshToken.Remove(savedToken); _context.SaveChanges(); return(null); } return(savedToken.Token); }
public async Task <Post> DeletePost(int postId) { var item = await _context.Post.Include(it => it.Comment) .Include(it => it.MediaLink) .Include(it => it.Collection) .FirstOrDefaultAsync(it => it.PostId == postId); if (item == null) { return(null); } _context.MediaLink.RemoveRange(item.MediaLink); _context.Comment.RemoveRange(item.Comment); _context.Collection.RemoveRange(item.Collection); _context.Post.Remove(item); _context.SaveChanges(); return(item); }
public async Task <UploadedImage> DeleteImage(string imageHash) { var image = await GetImage(imageHash); if (image == null) { return(null); } _context.UploadedImage.Remove(image); _context.SaveChanges(); return(image); }
public async Task <User> DeleteUser(string username) { var item = await GetUser(username); if (item == null) { return(null); } _context.RefreshToken.RemoveRange(_context.RefreshToken.Where(it => it.UserId == item.UserId)); _context.Comment.RemoveRange(_context.Comment.Where(it => it.UserId == item.UserId)); _context.User.Remove(item); _context.SaveChanges(); return(item); }