110 lines
3.3 KiB
C#
110 lines
3.3 KiB
C#
using LiteDB;
|
|
using skydiveLogs_api.Domain;
|
|
using skydiveLogs_api.DomainService.Repositories;
|
|
using skydiveLogs_api.Infrastructure.Interfaces;
|
|
using System.Collections.Generic;
|
|
|
|
namespace skydiveLogs_api.Infrastructure
|
|
{
|
|
public class GearRepository : IGearRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="GearRepository"/> class
|
|
/// </summary>
|
|
/// <param name="dataProvider">The data provider to use for data access</param>
|
|
public GearRepository(IDataProvider dataProvider)
|
|
{
|
|
_dataProvider = dataProvider;
|
|
_col = _dataProvider.CollOfGear;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Adds a new gear item to the database
|
|
/// </summary>
|
|
/// <param name="newGear">The gear instance to add</param>
|
|
/// <returns>The number of rows affected (0 if insert failed)</returns>
|
|
public int Add(Gear newGear)
|
|
{
|
|
int result;
|
|
|
|
try
|
|
{
|
|
var tmp = _col.Insert(newGear);
|
|
result = tmp.AsInt32;
|
|
}
|
|
catch
|
|
{
|
|
result = 0;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all gear items from the database
|
|
/// </summary>
|
|
/// <returns>A collection of all gear instances</returns>
|
|
public IEnumerable<Gear> GetAll()
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all gear items for a specific user
|
|
/// </summary>
|
|
/// <param name="user">The user whose gear items to retrieve</param>
|
|
/// <returns>A collection of gear instances belonging to the user</returns>
|
|
public IEnumerable<Gear> GetAll(User user)
|
|
{
|
|
return _col.Include(x => x.User)
|
|
.Query()
|
|
.Where(j => j.User.Id == user.Id)
|
|
.ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves a gear item by its unique identifier
|
|
/// </summary>
|
|
/// <param name="id">The unique identifier of the gear</param>
|
|
/// <returns>The gear instance or null if not found</returns>
|
|
public Gear GetById(int id)
|
|
{
|
|
return _col.FindById(new BsonValue(id));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the total count of gear items in the database
|
|
/// </summary>
|
|
/// <returns>The total number of gear items</returns>
|
|
public int GetCount()
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates an existing gear item in the database
|
|
/// </summary>
|
|
/// <param name="updatedGear">The gear instance to update</param>
|
|
/// <returns>True if the update was successful, false otherwise</returns>
|
|
public bool Update(Gear updatedGear)
|
|
{
|
|
return _col.Update(updatedGear);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly ILiteCollection<Gear> _col;
|
|
private readonly IDataProvider _dataProvider;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
}
|