예제 #1
0
        public async Task <IReminder> Create(DateTime triggerTime, string prelude, string msg, ulong channelId, ulong userId)
        {
            try
            {
                uint id;
                using (var cmd = _database.CreateCommand())
                {
                    cmd.CommandText = InsertReminder;
                    cmd.Parameters.Add(new SQLiteParameter("@InstantUnix", System.Data.DbType.String)
                    {
                        Value = triggerTime.UnixTimestamp()
                    });
                    cmd.Parameters.Add(new SQLiteParameter("@ChannelId", System.Data.DbType.String)
                    {
                        Value = channelId.ToString()
                    });
                    cmd.Parameters.Add(new SQLiteParameter("@Prelude", System.Data.DbType.String)
                    {
                        Value = prelude
                    });
                    cmd.Parameters.Add(new SQLiteParameter("@Message", System.Data.DbType.String)
                    {
                        Value = msg
                    });
                    cmd.Parameters.Add(new SQLiteParameter("@UserId", System.Data.DbType.String)
                    {
                        Value = userId.ToString()
                    });

                    id = (uint)(long)await cmd.ExecuteScalarAsync();
                }

                var reminder = new Reminder(id, triggerTime, prelude, msg, channelId, userId);

                ReminderCreated?.Invoke(reminder);

                return(reminder);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #2
0
        public async Task <IReminder> Create(DateTime triggerTime, string prelude, string msg, ulong channelId, ulong userId)
        {
            try
            {
                var reminder = new Reminder(0, triggerTime, prelude, msg, channelId, userId);
                await using (var cmd = _database.CreateCommand())
                {
                    cmd.CommandText = InsertReminder;
                    reminder.Write(cmd);
                    reminder = reminder.WithId((uint)(long)(await cmd.ExecuteScalarAsync()) !);
                }

                ReminderCreated?.Invoke(reminder);

                return(reminder);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }