75 lines
1.8 KiB
C#
75 lines
1.8 KiB
C#
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 UserStatsRepository : IUserStatsRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
public UserStatsRepository(IDataProvider dataProvider)
|
|
{
|
|
_dataProvider = dataProvider;
|
|
_col = _dataProvider.CollOfStats;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
public int Add(UserStats newStats)
|
|
{
|
|
int result;
|
|
|
|
try
|
|
{
|
|
var tmp = _col.Insert(newStats);
|
|
result = tmp.AsInt32;
|
|
}
|
|
catch
|
|
{
|
|
result = 0;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public IEnumerable<UserStats> GetAll()
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public UserStats GetAll(User user)
|
|
{
|
|
return _col.Include(x => x.User)
|
|
.Query()
|
|
.Where(j => j.User.Id == user.Id)
|
|
.SingleOrDefault();
|
|
}
|
|
|
|
public UserStats GetById(int id)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public bool Update(UserStats stats)
|
|
{
|
|
//col.UpdateMany(x => new Customer { Name
|
|
// = x.Name.ToUpper(), Salary: 100 }, x => x.Name == "John")
|
|
|
|
return _col.Update(stats);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly ILiteCollection<UserStats> _col;
|
|
private readonly IDataProvider _dataProvider;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |