Files
2022-05-08 16:42:04 +02:00

75 lines
1.7 KiB
C#

using LiteDB;
using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainService.Repositories;
using skydiveLogs_api.Infrastructure.Interfaces;
using System;
using System.Collections.Generic;
namespace skydiveLogs_api.Infrastructure
{
public class UserRepository : IUserRepository
{
#region Public Constructors
public UserRepository(IDataProvider dataProvider)
{
_dataProvider = dataProvider;
_col = _dataProvider.CollOfUser;
}
#endregion Public Constructors
#region Public Methods
public int Add(User newUser)
{
int result;
try
{
var tmp = _col.Insert(newUser);
result = tmp.AsInt32;
}
catch
{
result = 0;
}
return result;
}
public IEnumerable<User> GetAll()
{
throw new NotImplementedException();
}
public User GetById(int id)
{
return _col.FindById(new BsonValue(id));
}
public User GetByLogin(string login, string password)
{
return _col.FindOne(u => u.Login == login && u.Password == password);
}
public int GetCount()
{
throw new System.NotImplementedException();
}
public bool Update(User updated)
{
throw new NotImplementedException();
}
#endregion Public Methods
#region Private Fields
private readonly ILiteCollection<User> _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}