Пример #1
0
 public async Task SaveVkAcc(VkAcc vkAcc)
 {
     using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
     {
         db.VkAccs.Update(vkAcc);
         await db.SaveChangesAsync();
     }
 }
Пример #2
0
 public async Task ClearUncheckedClients(VkAcc vkAcc)
 {
     using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
     {
         var clients = db.VkClients.Where(e => e.VkAccId == vkAcc.VkAccId && e.ClientStatus == VkClient.Status.Unchecked);
         db.VkClients.RemoveRange(clients);
         await db.SaveChangesAsync();
     }
 }
Пример #3
0
 private async Task IncrementAddedFriends(VkAcc vkAcc)
 {
     using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
     {
         vkAcc.CountAddedFriends++;
         db.VkAccs.Update(vkAcc);
         await db.SaveChangesAsync();
     }
 }
Пример #4
0
 public async Task<VkClient> GetAcceptedClient(VkAcc vkAcc)
 {
     using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
     {
         return await db.VkClients
         .Include(e => e.VkAcc)
         .FirstOrDefaultAsync(
             e => e.ClientStatus == VkClient.Status.Accepted
             && e.VkAcc.VkAccId == vkAcc.VkAccId);
     }
 }
Пример #5
0
        public async Task SetClientStatus(int id, VkClient.Status Status)
        {
            using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
            {
                db.VkClients
                .FirstOrDefault(e => e.VkClientId == id)
                .ClientStatus = Status;

                await db.SaveChangesAsync();
            }
        }
Пример #6
0
        public async Task RemoveVkAcc(VkAcc vkAcc)
        {
            using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
            {
                var user = await db.Users
                    .Include(e => e.VkAccs)
                    .FirstOrDefaultAsync(e => e.UserId == User.UserId);
                user.VkAccs.RemoveAll(e => e.VkAccId == vkAcc.VkAccId);

                await db.SaveChangesAsync();
            }
        }
Пример #7
0
        public async Task<Models.VkAcc> GetVkAcc(long VkAccId)
        {
            Models.VkAcc vkAcc;
            using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
            {
                vkAcc = db.VkAccs.FirstOrDefault(e => e.VkAccId == VkAccId);
                await UpdateVkAccStatus(vkAcc);
                await db.SaveChangesAsync();
            }
            return vkAcc;

        }
Пример #8
0
 private async Task UpdateClients(VkAcc vkAcc)
 {
     using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
     {
         int Count = 50;
         var acc = db.VkAccs.FirstOrDefault(e => e.VkAccId == vkAcc.VkAccId);
         vkAcc.VkClients.AddRange(await VkApisManager.GetNewClients(
             acc,
              Count, this, db));
         await db.SaveChangesAsync();
     }
 }
Пример #9
0
        private Models.User _getUserByTgChatId(long ChatId)
        {
            Models.User user;
            using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
            {
                user = db.Users
                .Include(e => e.VkAccs)
                .ThenInclude(e => e.VkClients)
                .FirstOrDefault(e => e.ChatId == ChatId);
                if (user == null)
                {
                    db.Users.Add(user = new Models.User() { ChatId = ChatId });
                    db.SaveChanges();
                }

            }
            return user;
        }
Пример #10
0
        public async Task<VkAcc> CreateVkAcc(string Token)
        {
            VkAcc vkAcc;
            var result = await VkApisManager.TryAuthorize(Token);
            if (result == true)
            {
                using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
                {
                    var user = await db.Users.FirstOrDefaultAsync(e => e.UserId == User.UserId);
                    vkAcc = new VkAcc()
                    {
                        AccessToken = Token,
                        FriendsLimit = 40,
                        CountAddedFriends = 0,
                    };
                    await this.UpdateVkAccStatus(vkAcc);
                    user.VkAccs.Add(vkAcc);

                    await db.SaveChangesAsync();
                }
                return vkAcc;
            }
            return null;
        }
Пример #11
0
        public async Task<List<Models.VkAcc>> GetVkAccs(bool NeedUpdate = false)
        {
            List<Models.VkAcc> vkAccs;
            using (var db = new ModelScoutDbContext(this._dbOptionsBuilder.Options))
            {
                if (User == null)
                    vkAccs = db.VkAccs
                        .Include(e => e.User)
                        .ToList();
                else
                    vkAccs = db.VkAccs
                        .Where(e => e.UserId == this.User.UserId)
                        .Include(e => e.User)
                        .ToList();
                if (NeedUpdate)
                {
                    foreach (var vkAcc in vkAccs)
                        await UpdateVkAccStatus(vkAcc);
                    await db.SaveChangesAsync();
                }
            }
            return vkAccs;

        }
Пример #12
0
        internal static async Task <List <VkClient> > GetNewClients(
            VkAcc vkAcc, int Count, ModelScoutAPI api,
            ModelScoutDbContext context)
        {
            uint UpdatedCount = 0;
            uint Offset       = 0;

            List <VkClient> vkClients = new List <VkClient>();

            var vkApi = _getApi(vkAcc);

            if (!_isVkApiActive(vkApi))
            {
                return(null);
            }

            while (UpdatedCount < Count)
            {
                var clientsSearch = await vkApi.Users.SearchAsync(new UserSearchParams()
                {
                    City       = vkAcc.City,
                    Country    = vkAcc.Country,
                    AgeFrom    = (ushort)vkAcc.AgeFrom,
                    AgeTo      = (ushort)vkAcc.AgeTo,
                    Sex        = (VkNet.Enums.Sex)vkAcc.Sex,
                    BirthMonth = (ushort)vkAcc.BirthMonth,
                    BirthDay   = (ushort)vkAcc.BirthDay,
                    Online     = true,
                    HasPhoto   = true,
                    Count      = (uint)Count,
                    Offset     = Offset,
                });

                foreach (var clientSearch in clientsSearch)
                {
                    //BAD CODE
                    if (!context.VkClients.Any(e => e.ProfileVkId == clientSearch.Id) && clientSearch.IsClosed != true)
                    //BAD CODE
                    {
                        var vkClient = new VkClient()
                        {
                            ClientStatus = VkClient.Status.Unchecked,
                            VkAccId      = vkAcc.VkAccId,
                            ProfileVkId  = (int)clientSearch.Id
                        };
                        //BAD CODE
                        vkAcc.VkClients.Add(vkClient);
                        //BAD CODE
                        vkClients.Add(vkClient);
                        UpdatedCount++;
                    }
                }

                Offset += (uint)Count;

                if (clientsSearch.TotalCount < Offset)
                {
                    break;
                }
            }
            return(vkClients);
        }