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

Implement Increment Iterator method

parent 2d7e3b56
......@@ -7,6 +7,7 @@ namespace Stratis.Guru.Models
public interface ISettings
{
Task InitAsync();
int GetIterator();
uint GetIterator();
void IncrementIterator();
}
}
\ No newline at end of file
......@@ -7,6 +7,6 @@ namespace Stratis.Guru.Models
{
[BsonId]
public ObjectId Id { get; set; }
public int PublicKeyIterator { get; set; }
public uint PublicKeyIterator { get; set; }
}
}
\ No newline at end of file
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace Stratis.Guru.Models
{
......@@ -12,8 +13,13 @@ namespace Stratis.Guru.Models
_databaseContext = databaseContext;
}
public int GetIterator() => _databaseContext.Settings.Find(x => true).FirstOrDefault().PublicKeyIterator;
public uint GetIterator() => _databaseContext.Settings.Find(x => true).FirstOrDefault().PublicKeyIterator;
public void IncrementIterator()
{
var itemId =_databaseContext.Settings.Find(x => true).FirstOrDefault().Id;
_databaseContext.Settings.FindOneAndUpdate(Builders<Setting>.Filter.Eq("_id", itemId), Builders<Setting>.Update.Inc(c => c.PublicKeyIterator, (uint)1), new FindOneAndUpdateOptions<Setting> { IsUpsert = true});
}
public async Task InitAsync()
{
......
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