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 /// /// Initializes a new instance of the class /// /// The data provider to use for data access public UserRepository(IDataProvider dataProvider) { _dataProvider = dataProvider; _col = _dataProvider.CollOfUser; } #endregion Public Constructors #region Public Methods /// /// Adds a new user to the database /// /// The user instance to add /// The number of rows affected (0 if insert failed) public int Add(User newUser) { int result; try { var tmp = _col.Insert(newUser); result = tmp.AsInt32; } catch { result = 0; } return result; } /// /// Retrieves all users from the database /// /// A collection of all user instances public IEnumerable GetAll() { throw new NotImplementedException(); } /// /// Retrieves a user by its unique identifier /// /// The unique identifier of the user /// The user instance or null if not found public User GetById(int id) { return _col.FindById(new BsonValue(id)); } /// /// Retrieves a user by their login credentials /// /// The user's login /// The user's password /// The user instance or null if not found public User GetByLogin(string login, string password) { return _col.FindOne(u => u.Login == login && u.Password == password); } /// /// Gets the total count of users in the database /// /// The total number of users public int GetCount() { throw new System.NotImplementedException(); } /// /// Updates an existing user in the database /// /// The user instance to update /// True if the update was successful, false otherwise public bool Update(User updated) { throw new NotImplementedException(); } #endregion Public Methods #region Private Fields private readonly ILiteCollection _col; private readonly IDataProvider _dataProvider; #endregion Private Fields } }