async Task AddInQueryAsync(string chatId, string query) { using (var db = new DbNorthwind()) { await db.InsertAsync(new Querys() { Date = DateTime.Now, Query = query, ChatId = chatId }); } }
async Task AddQuery(string chatId, string query, List <WeaponList> reslist) { using (var db = new DbNorthwind()) { await db.ViewsTurns .Where(w => w.ChatId == int.Parse(chatId)) .DeleteAsync(); var list = reslist .OrderByDescending(w => w.StartTime) .Take(100) .ToList(); list = list.GroupBy(f => f.Text) .Select(g => g.First()).Take(50).ToList(); var turnsList = new List <ViewsTurns>(); foreach (var item in list) { turnsList.Add(new ViewsTurns() { ChatId = int.Parse(chatId), WeaponListId = item.Id, }); } db.ViewsTurns.BulkCopy(turnsList); var queryClass = await db.LastQuery.FirstOrDefaultAsync(w => w.ChatId == chatId); if (queryClass == null) { await db.InsertAsync(new LastQuery { ChatId = chatId, Query = query }); } else { await db.LastQuery .Where(w => w.Id == queryClass.Id) .Set(s => s.Query, query) .UpdateAsync(); } } }