Split tables for the stats (#6)
Reviewed-on: #6 Co-authored-by: sandre <perso@sebastienandre.com> Co-committed-by: sandre <perso@sebastienandre.com>
This commit was merged in pull request #6.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
using LiteDB;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsForLastYearByDzRepository : IStatsForLastYearByDzRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public StatsForLastYearByDzRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfStatsForLastYearByDz;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(IEnumerable<StatsForLastYearByDz> newStats)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<StatsForLastYearByDz> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(IEnumerable<StatsForLastYearByDz> updatedStats, User user)
|
||||
{
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly ILiteCollection<StatsForLastYearByDz> _col;
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user