Commit 8d1f3047 authored by Clint.Network's avatar Clint.Network

Add InitLottery()

parent ff1bde4e
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace Stratis.Guru.Services
{
public class LotterySetting
{
[BsonId]
public ObjectId Id { get; set; }
public int PublicKeyIterator { get; set; }
}
}
\ No newline at end of file
...@@ -21,9 +21,26 @@ namespace Stratis.Guru.Services ...@@ -21,9 +21,26 @@ namespace Stratis.Guru.Services
public async Task StartAsync(CancellationToken cancellationToken) public async Task StartAsync(CancellationToken cancellationToken)
{ {
await InitLottery();
await CalculateNextDrawAsync(); await CalculateNextDrawAsync();
} }
private async Task InitLottery()
{
#region use DI
var client = new MongoClient("mongodb://localhost:27017");
var database = client.GetDatabase("stratis-guru");
var collection = database.GetCollection<LotterySetting>("lottery");
if(!collection.Find(x => true).Any())
{
await collection.InsertOneAsync(new LotterySetting()
{
PublicKeyIterator = 0
});
}
#endregion
}
private async Task CalculateNextDrawAsync() private async Task CalculateNextDrawAsync()
{ {
DateTime today = DateTime.Today; DateTime today = DateTime.Today;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment