78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
using skydiveLogs_api.Domain;
|
|
using skydiveLogs_api.DomainBusiness.Interfaces;
|
|
using skydiveLogs_api.DomainService.Repositories;
|
|
using skydiveLogs_api.Infrastructure;
|
|
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
|
|
|
|
public void AddNewJumpType(JumpType newJumpType)
|
|
{
|
|
_jumpTypeRepository.Add(newJumpType);
|
|
_cacheService.Delete(CacheType.JumpType);
|
|
}
|
|
|
|
public void DeleteJumpTypeById(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public IEnumerable<JumpType> GetAllJumpTypes()
|
|
{
|
|
if (!_cacheService.Contains(CacheType.JumpType))
|
|
_cacheService.Put(CacheType.JumpType,
|
|
_jumpTypeRepository.GetAll(),
|
|
5 * 60 * 1000);
|
|
|
|
return _cacheService.Get<IEnumerable<JumpType>>(CacheType.JumpType);
|
|
}
|
|
|
|
public IEnumerable<JumpType> GetJumpTypesForTunnel()
|
|
{
|
|
return GetAllJumpTypes().Where(t => t.InTunnel);
|
|
}
|
|
|
|
public JumpType GetJumpTypeById(int id)
|
|
{
|
|
var allJumpTypes = GetAllJumpTypes();
|
|
return allJumpTypes.Single(g => g.Id == id);
|
|
}
|
|
|
|
public bool UpdateJumpType(int id, JumpType jumpType)
|
|
{
|
|
jumpType.Id = id;
|
|
|
|
var result = _jumpTypeRepository.Update(jumpType);
|
|
if (result)
|
|
_cacheService.Delete(CacheType.JumpType);
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly ICacheService _cacheService;
|
|
private readonly IJumpTypeRepository _jumpTypeRepository;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |