Esempio n. 1
0
        public async Task ExecuteRandomLike(int userId)
        {
            await using var scope = _transactionScopeFactory.CreateQuery();

            var favouriteGroup = await scope
                                 .RawSql <FavouriteGroup>(
                $"select * from public.\"FavouriteGroup\" where \"{nameof(FavouriteGroup.UserId)}\" = {userId} order by random() limit 1")
                                 .Select(f => f.GroupId)
                                 .FirstOrDefaultAsync();

            if (favouriteGroup != default)
            {
                using var user = _securityUserManager.SetUser(new SecurityUser { Id = userId });
                var rnd  = new Random();
                var post = (await _vkClient.WallSearch(favouriteGroup, rnd.Next(1, 30), 1))?.Response?.Items
                           ?.FirstOrDefault();

                if (post != default && !(post.Likes?.UserLikes ?? true))
                {
                    await Task.Delay(300);

                    await _vkLikeService.Like(new VkRepostViewModel(post.OwnerId, post.Id));
                }

                _backgroundJobService.Schedule <IRandomLikeService>(x => x.ExecuteRandomLike(userId),
                                                                    TimeSpan.FromMilliseconds(rnd.Next(60 * 1000 * 3, 60 * 1000 * 60 * 5)));
            }
        }
        public async Task <int> Handle(CreateOrderCommand command, CancellationToken cancellationToken)
        {
            var order = _mapper.Map <Order>(command.Dto);

            order.CreateDate = DateTime.UtcNow;
            _dbContext.Orders.Add(order);
            await _dbContext.SaveChangesAsync();

            _backgroundJobService.Schedule <IEmailService>(emailService => emailService.SendAsync(_currentUserService.Email, "Order created", $"Order {order.Id} created"));
            return(order.Id);
        }