98 lines
2.8 KiB
C#
98 lines
2.8 KiB
C#
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 AircraftRepository : IAircraftRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="AircraftRepository"/> class
|
|
/// </summary>
|
|
/// <param name="dataProvider">The data provider to use for data access</param>
|
|
public AircraftRepository(IDataProvider dataProvider)
|
|
{
|
|
_dataProvider = dataProvider;
|
|
_col = _dataProvider.CollOfAircraft;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Adds a new aircraft to the database
|
|
/// </summary>
|
|
/// <param name="newAircraft">The aircraft instance to add</param>
|
|
/// <returns>The number of rows affected (0 if insert failed)</returns>
|
|
public int Add(Aircraft newAircraft)
|
|
{
|
|
int result;
|
|
|
|
try
|
|
{
|
|
var tmp = _col.Insert(newAircraft);
|
|
result = tmp.AsInt32;
|
|
}
|
|
catch
|
|
{
|
|
result = 0;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all aircraft from the database
|
|
/// </summary>
|
|
/// <returns>A collection of all aircraft instances</returns>
|
|
public IEnumerable<Aircraft> GetAll()
|
|
{
|
|
return _col.FindAll().ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves an aircraft by its unique identifier
|
|
/// </summary>
|
|
/// <param name="id">The unique identifier of the aircraft</param>
|
|
/// <returns>The aircraft instance or null if not found</returns>
|
|
public Aircraft GetById(int id)
|
|
{
|
|
return _col.FindById(new BsonValue(id));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the total count of aircraft in the database
|
|
/// </summary>
|
|
/// <returns>The total number of aircraft</returns>
|
|
public int GetCount()
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates an existing aircraft in the database
|
|
/// </summary>
|
|
/// <param name="aircraft">The aircraft instance to update</param>
|
|
/// <returns>True if the update was successful, false otherwise</returns>
|
|
public bool Update(Aircraft aircraft)
|
|
{
|
|
return _col.Update(aircraft);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly ILiteCollection<Aircraft> _col;
|
|
private readonly IDataProvider _dataProvider;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
}
|