From ca5f2a3d8f137bf71d64d2eac9a3289f4a7847bb Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Mon, 8 Feb 2016 20:38:03 +0100 Subject: [PATCH] moved time to IDataModel, started making currency stuff --- NadekoBot/Classes/DBHandler.cs | 6 +++--- NadekoBot/Classes/_DataModels/AnnouncementModel.cs | 2 -- NadekoBot/Classes/_DataModels/CommandModel.cs | 2 -- NadekoBot/Classes/_DataModels/Currency.cs | 6 ++++++ NadekoBot/Classes/_DataModels/CurrencyTransaction.cs | 6 ++++++ NadekoBot/Classes/_DataModels/IDataModel.cs | 6 ++---- NadekoBot/Classes/_DataModels/RequestModel.cs | 6 +----- NadekoBot/Classes/_DataModels/StatsModel.cs | 2 -- NadekoBot/Classes/_DataModels/TypingArticleModel.cs | 6 +----- NadekoBot/NadekoBot.csproj | 2 ++ 10 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 NadekoBot/Classes/_DataModels/Currency.cs create mode 100644 NadekoBot/Classes/_DataModels/CurrencyTransaction.cs diff --git a/NadekoBot/Classes/DBHandler.cs b/NadekoBot/Classes/DBHandler.cs index 6cd5adf9..9dcf325e 100644 --- a/NadekoBot/Classes/DBHandler.cs +++ b/NadekoBot/Classes/DBHandler.cs @@ -41,13 +41,13 @@ namespace NadekoBot.Classes { internal List GetAllRows() where T : IDataModel, new() { using (var _conn = new SQLiteConnection(_filePath)) { - return _conn.Table().Where(t => true).ToList(); + return _conn.Table().ToList(); } } internal T Delete(int Id) where T : IDataModel, new() { using (var _conn = new SQLiteConnection(_filePath)) { - var found = _conn.Table().Where(t => t.Id == Id).FirstOrDefault(); + var found = _conn.Find(Id); if (found != null) _conn.Delete(found.Id); return found; @@ -59,7 +59,7 @@ namespace NadekoBot.Classes { /// internal void Save(T o) where T : IDataModel, new() { using (var _conn = new SQLiteConnection(_filePath)) { - var found = _conn.Table().Where(t => t.Id == o.Id).FirstOrDefault(); + var found = _conn.Find(o.Id); if (found == null) _conn.Insert(o, typeof(T)); else diff --git a/NadekoBot/Classes/_DataModels/AnnouncementModel.cs b/NadekoBot/Classes/_DataModels/AnnouncementModel.cs index 542333bc..21e5a9c1 100644 --- a/NadekoBot/Classes/_DataModels/AnnouncementModel.cs +++ b/NadekoBot/Classes/_DataModels/AnnouncementModel.cs @@ -14,7 +14,5 @@ namespace NadekoBot.Classes._DataModels { [JsonProperty("byeChannel")] public long ByeChannelId { get; set; } = 0; public string ByeText { get; set; } = "%user% has left the server."; - [JsonProperty("createdAt")] - public DateTime DateAdded { get; set; } = DateTime.Now; } } diff --git a/NadekoBot/Classes/_DataModels/CommandModel.cs b/NadekoBot/Classes/_DataModels/CommandModel.cs index 03cb9656..4a09253a 100644 --- a/NadekoBot/Classes/_DataModels/CommandModel.cs +++ b/NadekoBot/Classes/_DataModels/CommandModel.cs @@ -9,7 +9,5 @@ namespace NadekoBot.Classes._DataModels { public long ChannelId { get; set; } public string ChannelName { get; set; } public string CommandName { get; set; } - [Newtonsoft.Json.JsonProperty("createdAt")] - public DateTime DateAdded { get; set; } } } diff --git a/NadekoBot/Classes/_DataModels/Currency.cs b/NadekoBot/Classes/_DataModels/Currency.cs new file mode 100644 index 00000000..b090db92 --- /dev/null +++ b/NadekoBot/Classes/_DataModels/Currency.cs @@ -0,0 +1,6 @@ +namespace NadekoBot.Classes._DataModels { + class Currency : IDataModel { + public long UserId { get; set; } + public long Value { get; set; } + } +} diff --git a/NadekoBot/Classes/_DataModels/CurrencyTransaction.cs b/NadekoBot/Classes/_DataModels/CurrencyTransaction.cs new file mode 100644 index 00000000..1cde21f3 --- /dev/null +++ b/NadekoBot/Classes/_DataModels/CurrencyTransaction.cs @@ -0,0 +1,6 @@ +namespace NadekoBot.Classes._DataModels { + class CurrencyTransaction : IDataModel { + public string Reason { get; set; } + public int Value { get; set; } + } +} diff --git a/NadekoBot/Classes/_DataModels/IDataModel.cs b/NadekoBot/Classes/_DataModels/IDataModel.cs index 891cc04e..d2dc0b04 100644 --- a/NadekoBot/Classes/_DataModels/IDataModel.cs +++ b/NadekoBot/Classes/_DataModels/IDataModel.cs @@ -1,14 +1,12 @@ using SQLite; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace NadekoBot.Classes._DataModels { class IDataModel { [PrimaryKey, AutoIncrement] public int Id { get; set; } + [Newtonsoft.Json.JsonProperty("createdAt")] + public DateTime DateAdded { get; set; } = DateTime.Now; public IDataModel() { } } } diff --git a/NadekoBot/Classes/_DataModels/RequestModel.cs b/NadekoBot/Classes/_DataModels/RequestModel.cs index 6fda3c83..909fa629 100644 --- a/NadekoBot/Classes/_DataModels/RequestModel.cs +++ b/NadekoBot/Classes/_DataModels/RequestModel.cs @@ -1,6 +1,4 @@ -using System; - -namespace NadekoBot.Classes._DataModels { +namespace NadekoBot.Classes._DataModels { class Request : IDataModel { public string UserName { get; set; } public long UserId { get; set; } @@ -8,7 +6,5 @@ namespace NadekoBot.Classes._DataModels { public long ServerId { get; set; } [Newtonsoft.Json.JsonProperty("Request")] public string RequestText { get; set; } - [Newtonsoft.Json.JsonProperty("createdAt")] - public DateTime DateAdded { get; set; } } } diff --git a/NadekoBot/Classes/_DataModels/StatsModel.cs b/NadekoBot/Classes/_DataModels/StatsModel.cs index 22b64d9b..7ab8c97c 100644 --- a/NadekoBot/Classes/_DataModels/StatsModel.cs +++ b/NadekoBot/Classes/_DataModels/StatsModel.cs @@ -6,7 +6,5 @@ namespace NadekoBot.Classes._DataModels { public int OnlineUsers { get; set; } public TimeSpan Uptime { get; set; } public int RealOnlineUsers { get; set; } - [Newtonsoft.Json.JsonProperty("createdAt")] - public DateTime DateAdded { get; set; } } } diff --git a/NadekoBot/Classes/_DataModels/TypingArticleModel.cs b/NadekoBot/Classes/_DataModels/TypingArticleModel.cs index 3a81f74c..cd605772 100644 --- a/NadekoBot/Classes/_DataModels/TypingArticleModel.cs +++ b/NadekoBot/Classes/_DataModels/TypingArticleModel.cs @@ -1,9 +1,5 @@ -using System; - -namespace NadekoBot.Classes._DataModels { +namespace NadekoBot.Classes._DataModels { class TypingArticle : IDataModel { public string Text { get; set; } - [Newtonsoft.Json.JsonProperty("createdAt")] - public DateTime DateAdded { get; set; } } } diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index fb1cbfb8..8541cb0f 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -133,6 +133,8 @@ + +