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 FavoriteDropZoneRepository : IFavoriteDropZoneRepository
{
#region Public Constructors
///
/// Initializes a new instance of the class
///
/// The data provider to use for data access
public FavoriteDropZoneRepository(IDataProvider dataProvider)
{
_dataProvider = dataProvider;
_col = _dataProvider.CollOfFavoriteDropZone;
}
#endregion Public Constructors
#region Public Methods
///
/// Adds a new favorite drop zone to the database
///
/// The favorite drop zone instance to add
/// The number of rows affected (0 if insert failed)
public int Add(FavoriteDropZone favoriteToAdd)
{
int result;
try
{
var tmp = _col.Insert(favoriteToAdd);
result = tmp.AsInt32;
}
catch
{
result = 0;
}
return result;
}
///
/// Deletes a favorite drop zone by drop zone ID and user ID
///
/// The unique identifier of the drop zone
/// The unique identifier of the user
/// The number of rows affected (0 if delete failed)
public int Delete(int dropZoneId, int userId)
{
return _col.DeleteMany(d => d.DropZone.Id == dropZoneId && d.User.Id == userId);
}
///
/// Retrieves all favorite drop zones for a specific user
///
/// The user whose favorite drop zones to retrieve
/// A collection of favorite drop zone instances belonging to the user
public IEnumerable GetAll(User user)
{
return _col.Query()
.Where(j => j.User.Id == user.Id)
.ToList();
}
///
/// Retrieves all favorite drop zones from the database
///
/// A collection of all favorite drop zone instances
public IEnumerable GetAll()
{
throw new System.NotImplementedException();
}
///
/// Retrieves a favorite drop zone by its unique identifier
///
/// The unique identifier of the favorite drop zone
/// The favorite drop zone instance or null if not found
public FavoriteDropZone GetById(int id)
{
throw new System.NotImplementedException();
}
///
/// Gets the total count of favorite drop zones in the database
///
/// The total number of favorite drop zones
public int GetCount()
{
throw new System.NotImplementedException();
}
///
/// Updates an existing favorite drop zone in the database
///
/// The favorite drop zone instance to update
/// True if the update was successful, false otherwise
public bool Update(FavoriteDropZone updated)
{
throw new System.NotImplementedException();
}
#endregion Public Methods
#region Private Fields
private readonly ILiteCollection _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}