Files
SkydiveLogs/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs
T
2026-04-17 17:26:20 +02:00

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