Ejemplo n.º 1
0
 public async Task InitializeAsync()
 {
     using var db = new VbContext();
     _quotes      = await db.Set <T>()
                    .OrderBy(x => x.Id)
                    .ToListAsync();
 }
Ejemplo n.º 2
0
        private async Task AddQuoteAsync(OnChatCommandReceivedArgs e)
        {
            if (e.Command.ArgumentsAsString.Length > 280)
            {
                _client.SendMessage(e, $"@{e.Command.ChatMessage.Username}: Quote is too long, not added.");
                return;
            }

            var quoteRecord = new T
            {
                Quote   = e.Command.ArgumentsAsString.Trim('"'),
                AddedBy = e.Command.ChatMessage.Username,
                AddedAt = DateTime.UtcNow
            };

            _quotes.Add(quoteRecord);

            using (var db = new VbContext())
            {
                db.Set <T>().Add(quoteRecord);
                await db.SaveChangesAsync();
            }

            _client.SendMessage(e, $"@{e.Command.ChatMessage.Username}: {_name} quote added.");
        }