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 JumpTypeService : IJumpTypeService { #region Public Constructors public JumpTypeService(IJumpTypeRepository jumpTypeRepository, ICacheService cacheService) { _jumpTypeRepository = jumpTypeRepository; _cacheService = cacheService; } #endregion Public Constructors #region Public Methods /// /// Adds a new jump type to the system. /// /// The JumpType entity containing the new jump type data. public void AddNewJumpType(JumpType newJumpType) { _jumpTypeRepository.Add(newJumpType); _cacheService.Delete(CacheType.JumpType); } /// /// Deletes a jump type by its ID. /// /// The jump type ID to delete. public void DeleteJumpTypeById(int id) { throw new NotImplementedException(); } /// /// Retrieves all jump types. /// /// A collection of JumpType entities containing all jump types. public IEnumerable GetAllJumpTypes() { if (!_cacheService.Contains(CacheType.JumpType)) _cacheService.Put(CacheType.JumpType, _jumpTypeRepository.GetAll(), 5 * 60 * 1000); return _cacheService.Get>(CacheType.JumpType); } /// /// Retrieves jump types specifically used for tunnel operations. /// /// A collection of JumpType entities containing tunnel jump types. public IEnumerable GetJumpTypesForTunnel() { return GetAllJumpTypes().Where(t => t.InTunnel); } /// /// Retrieves a jump type by its ID. /// /// The jump type ID to retrieve. /// A JumpType entity containing the jump type details. public JumpType GetJumpTypeById(int id) { var allJumpTypes = GetAllJumpTypes(); return allJumpTypes.Single(g => g.Id == id); } /// /// Updates an existing jump type. /// /// The jump type ID to update. /// JumpType entity containing the updated jump type data. /// Whether to reset the cache after update. /// True if the update was successful, false otherwise. public bool UpdateJumpType(int id, JumpType jumpType, bool resetCache = true) { jumpType.Id = id; var result = _jumpTypeRepository.Update(jumpType); if (resetCache && result) _cacheService.Delete(CacheType.JumpType); return result; } #endregion Public Methods #region Private Fields private readonly ICacheService _cacheService; private readonly IJumpTypeRepository _jumpTypeRepository; #endregion Private Fields } }