예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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));
            }
        }
예제 #4
0
 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);
         }
     });
 }
예제 #5
0
 public void Delete(IReadOnlyCollection <Message> messages)
 {
     context.RemoveRange(messages);
     context.SaveChanges();
 }