Add controler, domain and service about "Tunnel"
This commit is contained in:
@@ -87,6 +87,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
public bool RemoveToFavorite(int dzId)
|
||||
{
|
||||
var result = _favoriteDropZoneRepository.Delete(dzId, _identityService.ConnectedUser.Id);
|
||||
_cacheService.Delete(CacheType.DropZone);
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
@@ -95,7 +96,11 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
dropZone.Id = id;
|
||||
|
||||
return _dropZoneRepository.Update(dropZone);
|
||||
var result = _dropZoneRepository.Update(dropZone);
|
||||
if (result)
|
||||
_cacheService.Delete(CacheType.DropZone);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private IEnumerable<DropZone> GetAllRefDzs()
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface ITunnelService
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Tunnel> GetAllTunnels();
|
||||
|
||||
Tunnel GetTunnelById(int id);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
67
Back/skydiveLogs-api.DomainBusiness/TunnelService.cs
Normal file
67
Back/skydiveLogs-api.DomainBusiness/TunnelService.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
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 TunnelService : ITunnelService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public TunnelService(IDropZoneRepository dropZoneRepository,
|
||||
ICacheService cacheService)
|
||||
{
|
||||
_dropZoneRepository = dropZoneRepository;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public IEnumerable<Tunnel> GetAllTunnels()
|
||||
{
|
||||
return GetAllRefTunnels();
|
||||
}
|
||||
|
||||
public Tunnel GetTunnelById(int id)
|
||||
{
|
||||
var allTunnels = GetAllRefTunnels();
|
||||
return allTunnels.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
private IEnumerable<Tunnel> GetAllRefTunnels()
|
||||
{
|
||||
if (!_cacheService.Contains(CacheType.Tunnel))
|
||||
{
|
||||
var tmp = _dropZoneRepository.GetAll()
|
||||
.Where(d => d.Type.Contains("tunnel"))
|
||||
.Select(t => new Tunnel
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
Website = t.Website,
|
||||
Address = t.Address,
|
||||
Email = t.Email,
|
||||
Latitude = t.Latitude,
|
||||
Longitude = t.Longitude
|
||||
});
|
||||
_cacheService.Put(CacheType.Tunnel, tmp, 5 * 60 * 1000);
|
||||
}
|
||||
|
||||
return _cacheService.Get<IEnumerable<Tunnel>>(CacheType.Tunnel);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly IDropZoneRepository _dropZoneRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user