moved time to IDataModel, started making currency stuff

This commit is contained in:
Master Kwoth 2016-02-08 20:38:03 +01:00
parent 9beeaf6a0e
commit ca5f2a3d8f
10 changed files with 21 additions and 23 deletions

View File

@ -41,13 +41,13 @@ namespace NadekoBot.Classes {
internal List<T> GetAllRows<T>() where T : IDataModel, new() { internal List<T> GetAllRows<T>() where T : IDataModel, new() {
using (var _conn = new SQLiteConnection(_filePath)) { using (var _conn = new SQLiteConnection(_filePath)) {
return _conn.Table<T>().Where(t => true).ToList(); return _conn.Table<T>().ToList();
} }
} }
internal T Delete<T>(int Id) where T : IDataModel, new() { internal T Delete<T>(int Id) where T : IDataModel, new() {
using (var _conn = new SQLiteConnection(_filePath)) { using (var _conn = new SQLiteConnection(_filePath)) {
var found = _conn.Table<T>().Where(t => t.Id == Id).FirstOrDefault(); var found = _conn.Find<T>(Id);
if (found != null) if (found != null)
_conn.Delete<T>(found.Id); _conn.Delete<T>(found.Id);
return found; return found;
@ -59,7 +59,7 @@ namespace NadekoBot.Classes {
/// </summary> /// </summary>
internal void Save<T>(T o) where T : IDataModel, new() { internal void Save<T>(T o) where T : IDataModel, new() {
using (var _conn = new SQLiteConnection(_filePath)) { using (var _conn = new SQLiteConnection(_filePath)) {
var found = _conn.Table<T>().Where(t => t.Id == o.Id).FirstOrDefault(); var found = _conn.Find<T>(o.Id);
if (found == null) if (found == null)
_conn.Insert(o, typeof(T)); _conn.Insert(o, typeof(T));
else else

View File

@ -14,7 +14,5 @@ namespace NadekoBot.Classes._DataModels {
[JsonProperty("byeChannel")] [JsonProperty("byeChannel")]
public long ByeChannelId { get; set; } = 0; public long ByeChannelId { get; set; } = 0;
public string ByeText { get; set; } = "%user% has left the server."; public string ByeText { get; set; } = "%user% has left the server.";
[JsonProperty("createdAt")]
public DateTime DateAdded { get; set; } = DateTime.Now;
} }
} }

View File

@ -9,7 +9,5 @@ namespace NadekoBot.Classes._DataModels {
public long ChannelId { get; set; } public long ChannelId { get; set; }
public string ChannelName { get; set; } public string ChannelName { get; set; }
public string CommandName { get; set; } public string CommandName { get; set; }
[Newtonsoft.Json.JsonProperty("createdAt")]
public DateTime DateAdded { get; set; }
} }
} }

View File

@ -0,0 +1,6 @@
namespace NadekoBot.Classes._DataModels {
class Currency : IDataModel {
public long UserId { get; set; }
public long Value { get; set; }
}
}

View File

@ -0,0 +1,6 @@
namespace NadekoBot.Classes._DataModels {
class CurrencyTransaction : IDataModel {
public string Reason { get; set; }
public int Value { get; set; }
}
}

View File

@ -1,14 +1,12 @@
using SQLite; using SQLite;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Classes._DataModels { namespace NadekoBot.Classes._DataModels {
class IDataModel { class IDataModel {
[PrimaryKey, AutoIncrement] [PrimaryKey, AutoIncrement]
public int Id { get; set; } public int Id { get; set; }
[Newtonsoft.Json.JsonProperty("createdAt")]
public DateTime DateAdded { get; set; } = DateTime.Now;
public IDataModel() { } public IDataModel() { }
} }
} }

View File

@ -1,6 +1,4 @@
using System; namespace NadekoBot.Classes._DataModels {
namespace NadekoBot.Classes._DataModels {
class Request : IDataModel { class Request : IDataModel {
public string UserName { get; set; } public string UserName { get; set; }
public long UserId { get; set; } public long UserId { get; set; }
@ -8,7 +6,5 @@ namespace NadekoBot.Classes._DataModels {
public long ServerId { get; set; } public long ServerId { get; set; }
[Newtonsoft.Json.JsonProperty("Request")] [Newtonsoft.Json.JsonProperty("Request")]
public string RequestText { get; set; } public string RequestText { get; set; }
[Newtonsoft.Json.JsonProperty("createdAt")]
public DateTime DateAdded { get; set; }
} }
} }

View File

@ -6,7 +6,5 @@ namespace NadekoBot.Classes._DataModels {
public int OnlineUsers { get; set; } public int OnlineUsers { get; set; }
public TimeSpan Uptime { get; set; } public TimeSpan Uptime { get; set; }
public int RealOnlineUsers { get; set; } public int RealOnlineUsers { get; set; }
[Newtonsoft.Json.JsonProperty("createdAt")]
public DateTime DateAdded { get; set; }
} }
} }

View File

@ -1,9 +1,5 @@
using System; namespace NadekoBot.Classes._DataModels {
namespace NadekoBot.Classes._DataModels {
class TypingArticle : IDataModel { class TypingArticle : IDataModel {
public string Text { get; set; } public string Text { get; set; }
[Newtonsoft.Json.JsonProperty("createdAt")]
public DateTime DateAdded { get; set; }
} }
} }

View File

@ -133,6 +133,8 @@
<Compile Include="Classes\Music\SoundCloud.cs" /> <Compile Include="Classes\Music\SoundCloud.cs" />
<Compile Include="Classes\_DataModels\AnnouncementModel.cs" /> <Compile Include="Classes\_DataModels\AnnouncementModel.cs" />
<Compile Include="Classes\_DataModels\CommandModel.cs" /> <Compile Include="Classes\_DataModels\CommandModel.cs" />
<Compile Include="Classes\_DataModels\Currency.cs" />
<Compile Include="Classes\_DataModels\CurrencyTransaction.cs" />
<Compile Include="Classes\_DataModels\IDataModel.cs" /> <Compile Include="Classes\_DataModels\IDataModel.cs" />
<Compile Include="Classes\_DataModels\RequestModel.cs" /> <Compile Include="Classes\_DataModels\RequestModel.cs" />
<Compile Include="Classes\_DataModels\StatsModel.cs" /> <Compile Include="Classes\_DataModels\StatsModel.cs" />