public async Task DeleteUsersAsync(IEnumerable <long> usersId) { using (MessengerDbContext context = contextFactory.Create()) { var usersCondition = PredicateBuilder.New <User>(); usersCondition = usersId.Aggregate(usersCondition, (current, value) => current.Or(user => user.Id == value).Expand()); List <User> users = await context.Users.Where(usersCondition).ToListAsync().ConfigureAwait(false); context.RemoveRange(users); await context.SaveChangesAsync().ConfigureAwait(false); } }
public async Task DeleteNodesInformationAsync(IEnumerable <long> nodesIds) { using (MessengerDbContext context = contextFactory.Create()) { var nodesCondition = PredicateBuilder.New <Node>(); nodesCondition = nodesIds.Aggregate(nodesCondition, (current, value) => current.Or(opt => opt.Id == value).Expand()); List <Node> nodes = await context.Nodes.Where(nodesCondition).ToListAsync().ConfigureAwait(false); context.RemoveRange(nodes); await context.SaveChangesAsync().ConfigureAwait(false); } }
public async Task <List <KeyVm> > DeleteUserKeysAsync(IEnumerable <long> keysId, long userId) { using (MessengerDbContext context = contextFactory.Create()) { var keysCondition = PredicateBuilder.New <Key>(); keysCondition = keysId.Aggregate(keysCondition, (current, value) => current.Or(opt => opt.KeyId == value && opt.UserId == userId).Expand()); List <Key> keys = await context.Keys.Where(keysCondition).ToListAsync().ConfigureAwait(false); context.RemoveRange(keys); await context.SaveChangesAsync().ConfigureAwait(false); return(KeyConverter.GetKeysVm(keys)); } }
public static void StartRemoveExpiredMessagesTask() { Task.Run(async() => { while (true) { using (MessengerDbContext context = new MessengerDbContext()) { var expiredMessages = await context.Messages .Where(message => message.ExpiredAt <= DateTime.UtcNow.ToUnixTime() && message.ExpiredAt != null) .ToListAsync().ConfigureAwait(false); context.RemoveRange(expiredMessages); await context.SaveChangesAsync().ConfigureAwait(false); UsersConversationsCacheService.Instance.MessagesRemovedUpdateConversationsAsync(expiredMessages); } await AppServiceProvider.Instance.PendingMessagesService.RemoveExpiredAsync().ConfigureAwait(false); await Task.Delay(TimeSpan.FromMinutes(1)).ConfigureAwait(true); } }); }
public void Delete(IReadOnlyCollection <Message> messages) { context.RemoveRange(messages); context.SaveChanges(); }