Commit aa9811bd authored by Clint.Network's avatar Clint.Network

Add Draw ID

parent c4ede544
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Driver; using MongoDB.Driver;
...@@ -17,6 +18,11 @@ namespace Stratis.Guru.Models ...@@ -17,6 +18,11 @@ namespace Stratis.Guru.Models
_databaseContext = databaseContext; _databaseContext = databaseContext;
} }
public string GetLastDraw()
{
return _databaseContext.Draws.Find(x => true).ToList().OrderByDescending(x => x.DrawDate).FirstOrDefault().Id.ToString();
}
public async Task InitDrawAsync(long nextDrawTimestamp) public async Task InitDrawAsync(long nextDrawTimestamp)
{ {
if(!_databaseContext.Draws.Find(x => x.DrawDate.Equals(nextDrawTimestamp)).Any()) if(!_databaseContext.Draws.Find(x => x.DrawDate.Equals(nextDrawTimestamp)).Any())
......
...@@ -6,6 +6,7 @@ namespace Stratis.Guru.Models ...@@ -6,6 +6,7 @@ namespace Stratis.Guru.Models
{ {
public interface IDraws public interface IDraws
{ {
Task InitDrawAsync(long nextDrawTimestamp); Task InitDrawAsync(long nextDrawTimestamp);
string GetLastDraw();
} }
} }
\ No newline at end of file
...@@ -11,5 +11,6 @@ namespace Stratis.Guru.Models ...@@ -11,5 +11,6 @@ namespace Stratis.Guru.Models
public string WithdrawAddress { get; set; } public string WithdrawAddress { get; set; }
public BsonDateTime CreationDate { get; set; } public BsonDateTime CreationDate { get; set; }
public string Nickname { get; internal set; } public string Nickname { get; internal set; }
public string Draw { get; internal set; }
} }
} }
\ No newline at end of file
...@@ -5,21 +5,23 @@ namespace Stratis.Guru.Models ...@@ -5,21 +5,23 @@ namespace Stratis.Guru.Models
public class Participations : IParticipation public class Participations : IParticipation
{ {
private DatabaseContext _databaseContext; private DatabaseContext _databaseContext;
private IDraws _draws;
public Participations(DatabaseContext databaseContext) public Participations(DatabaseContext databaseContext, IDraws draws)
{ {
_databaseContext = databaseContext; _databaseContext = databaseContext;
_draws = draws;
} }
public void StoreParticipation(string ticket, string nickname, string address) public void StoreParticipation(string ticket, string nickname, string address)
{ {
//TODO: store lottery id
_databaseContext.Participations.InsertOne(new Participation _databaseContext.Participations.InsertOne(new Participation
{ {
CreationDate = DateTime.Now, CreationDate = DateTime.Now,
Ticket = ticket, Ticket = ticket,
Nickname = nickname, Nickname = nickname,
WithdrawAddress = address WithdrawAddress = address,
Draw = _draws.GetLastDraw()
}); });
} }
} }
......
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