Files
SkydiveLogs/Back/skydiveLogs-api.DomainBusiness/AircraftService.cs
Sébastien ANDRE 2b880231a1 Manage the update of some data at the
start of the database
2023-08-23 20:30:53 +02:00

72 lines
2.0 KiB
C#

using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
using skydiveLogs_api.DomainService.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
namespace skydiveLogs_api.DomainBusiness
{
public class AircraftService : IAircraftService
{
#region Public Constructors
public AircraftService(IAircraftRepository aircraftRepository,
ICacheService cacheService)
{
_aircraftRepository = aircraftRepository;
_cacheService = cacheService;
}
#endregion Public Constructors
#region Public Methods
public void AddNewAircraft(Aircraft newAircraft)
{
_aircraftRepository.Add(newAircraft);
_cacheService.Delete(CacheType.Aircraft);
}
public void DeleteAircraftById(int id)
{
throw new NotImplementedException();
}
public Aircraft GetAircraftById(int id)
{
var allAircrafts = GetAllAircrafts();
return allAircrafts.Single(g => g.Id == id);
}
public IEnumerable<Aircraft> GetAllAircrafts()
{
if (!_cacheService.Contains(CacheType.Aircraft))
_cacheService.Put(CacheType.Aircraft,
_aircraftRepository.GetAll(),
5 * 60 * 1000);
return _cacheService.Get<IEnumerable<Aircraft>>(CacheType.Aircraft);
}
public bool UpdateAircraft(int id, Aircraft aircraft, bool resetCache = true)
{
aircraft.Id = id;
var result = _aircraftRepository.Update(aircraft);
if (resetCache && result)
_cacheService.Delete(CacheType.JumpType);
return result;
}
#endregion Public Methods
#region Private Fields
private readonly IAircraftRepository _aircraftRepository;
private readonly ICacheService _cacheService;
#endregion Private Fields
}
}