public static async Task <int> SafeAddQuoteAsync(Server server, Quote quote) { using (var db = new KaguyaDb()) { await db.BeginTransactionAsync(); try { int id = await db.Servers .Where(s => s.ServerId == server.ServerId) .Select(s => s.NextQuoteId).FirstOrDefaultAsync(); quote.Id = id; int updateQuote = await db.InsertAsync(quote); IUpdatable <Server> statement = db.Servers .Where(s => s.ServerId == server.ServerId) .Set(i => i.NextQuoteId, id + 1); await db.CommitTransactionAsync(); return(id); } catch (Exception e) { await ConsoleLogger.LogAsync(e); await db.RollbackTransactionAsync(); } } return(-1); }