using LiteDB; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure.Interfaces; using System.Collections.Generic; using System.Linq; namespace skydiveLogs_api.Infrastructure { public class DropZoneRepository : IDropZoneRepository { #region Public Constructors /// /// Initializes a new instance of the class /// /// The data provider to use for data access public DropZoneRepository(IDataProvider dataProvider) { _dataProvider = dataProvider; _col = _dataProvider.CollOfDropZone; } #endregion Public Constructors #region Public Methods /// /// Adds a new drop zone to the database /// /// The drop zone instance to add /// The number of rows affected (0 if insert failed) public int Add(DropZone newDropZone) { int result; try { var tmp = _col.Insert(newDropZone); result = tmp.AsInt32; } catch { result = 0; } return result; } /// /// Retrieves all drop zones from the database /// /// A collection of all drop zone instances public IEnumerable GetAll() { return _col.FindAll().ToList(); } /// /// Retrieves a drop zone by its unique identifier /// /// The unique identifier of the drop zone /// The drop zone instance or null if not found public DropZone GetById(int id) { return _col.FindById(new BsonValue(id)); } /// /// Gets the total count of drop zones in the database /// /// The total number of drop zones public int GetCount() { throw new System.NotImplementedException(); } /// /// Updates an existing drop zone in the database /// /// The drop zone instance to update /// True if the update was successful, false otherwise public bool Update(DropZone dropZone) { return _col.Update(dropZone); } #endregion Public Methods #region Private Fields private readonly ILiteCollection _col; private readonly IDataProvider _dataProvider; #endregion Private Fields } }