Add a cache system on the referential info
+ Add an identity service
This commit is contained in:
@@ -1,23 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class AircraftService : IAircraftService
|
||||
{
|
||||
public AircraftService(IAircraftRepository aircraftRepository)
|
||||
#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)
|
||||
@@ -27,12 +35,18 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
public Aircraft GetAircraftById(int id)
|
||||
{
|
||||
return _aircraftRepository.GetById(id);
|
||||
var allAircrafts = GetAllAircrafts();
|
||||
return allAircrafts.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
public IEnumerable<Aircraft> GetAllAircrafts()
|
||||
{
|
||||
return _aircraftRepository.GetAll();
|
||||
if (!_cacheService.Contains(CacheType.Aircraft))
|
||||
_cacheService.Put(CacheType.Aircraft,
|
||||
_aircraftRepository.GetAll(),
|
||||
5 * 60 * 1000);
|
||||
|
||||
return _cacheService.Get<IEnumerable<Aircraft>>(CacheType.Aircraft);
|
||||
}
|
||||
|
||||
public void UpdateAircraft(int id, Aircraft aircraft)
|
||||
@@ -40,6 +54,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IAircraftRepository _aircraftRepository;
|
||||
private readonly ICacheService _cacheService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
51
Back/skydiveLogs-api.DomainBusiness/CacheService.cs
Normal file
51
Back/skydiveLogs-api.DomainBusiness/CacheService.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using System;
|
||||
using System.Runtime.Caching;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class CacheService : ICacheService
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
public bool Contains(CacheType type, int id = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
return MemoryCache.Default[key.ToString()] != null;
|
||||
}
|
||||
|
||||
public void Delete(CacheType type, int id = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
MemoryCache.Default.Remove(key.ToString());
|
||||
}
|
||||
|
||||
public T Get<T>(CacheType type, int id = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
return (T)MemoryCache.Default[key.ToString()];
|
||||
}
|
||||
|
||||
public void Put(CacheType type, object value, int duration, int id = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
if (duration <= 0)
|
||||
throw new ArgumentException("Duration cannot be less or equal to zero", "duration");
|
||||
|
||||
var policy = new CacheItemPolicy
|
||||
{
|
||||
AbsoluteExpiration = DateTime.Now.AddMilliseconds(duration)
|
||||
};
|
||||
|
||||
MemoryCache.Default.Set(key.ToString(), value, policy);
|
||||
}
|
||||
|
||||
private string GetKey(int id, CacheType type)
|
||||
{
|
||||
return $"{id}-{type}";
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class DropZoneService : IDropZoneService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public DropZoneService(IDropZoneRepository dropZoneRepository,
|
||||
IFavoriteDropZoneRepository favoriteDropZoneRepository)
|
||||
IFavoriteDropZoneRepository favoriteDropZoneRepository,
|
||||
IIdentityService identityService,
|
||||
ICacheService cacheService)
|
||||
{
|
||||
_dropZoneRepository = dropZoneRepository;
|
||||
_favoriteDropZoneRepository = favoriteDropZoneRepository;
|
||||
_identityService = identityService;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddNewDz(DropZone newdropZone)
|
||||
{
|
||||
_dropZoneRepository.Add(newdropZone);
|
||||
_cacheService.Delete(CacheType.DropZone);
|
||||
}
|
||||
|
||||
public bool AddToFavorite(int dzId)
|
||||
{
|
||||
var dzToAddToFavorite = GetDzById(dzId);
|
||||
|
||||
var favoriteDz = new FavoriteDropZone
|
||||
{
|
||||
DropZone = dzToAddToFavorite,
|
||||
User = _identityService.ConnectedUser
|
||||
};
|
||||
|
||||
var result = _favoriteDropZoneRepository.Add(favoriteDz);
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
public void DeleteDzById(int id)
|
||||
@@ -27,12 +52,12 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<DropZone> GetAllDzs(User connectedUser)
|
||||
public IEnumerable<DropZone> GetAllDzs()
|
||||
{
|
||||
var results = Enumerable.Empty<DropZone>();
|
||||
|
||||
var dropzones = _dropZoneRepository.GetAll();
|
||||
var favorites = _favoriteDropZoneRepository.GetAll(connectedUser);
|
||||
var dropzones = GetAllRefDzs();
|
||||
var favorites = _favoriteDropZoneRepository.GetAll(_identityService.ConnectedUser);
|
||||
|
||||
results = from dropZone in dropzones
|
||||
join favorite in favorites on dropZone.Id equals favorite.DropZone.Id into tmp
|
||||
@@ -55,7 +80,15 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
public DropZone GetDzById(int id)
|
||||
{
|
||||
return _dropZoneRepository.GetById(id);
|
||||
var allDzs = GetAllRefDzs();
|
||||
return allDzs.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
public bool RemoveToFavorite(int dzId)
|
||||
{
|
||||
var result = _favoriteDropZoneRepository.Delete(dzId, _identityService.ConnectedUser.Id);
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
public bool UpdateDz(int id, DropZone dropZone)
|
||||
@@ -65,30 +98,25 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return _dropZoneRepository.Update(dropZone);
|
||||
}
|
||||
|
||||
public bool AddToFavorite(int dzId, User connectedUser)
|
||||
private IEnumerable<DropZone> GetAllRefDzs()
|
||||
{
|
||||
var dzToAddToFavorite = GetDzById(dzId);
|
||||
if (!_cacheService.Contains(CacheType.DropZone))
|
||||
_cacheService.Put(CacheType.DropZone,
|
||||
_dropZoneRepository.GetAll(),
|
||||
5 * 60 * 1000);
|
||||
|
||||
var favoriteDz = new FavoriteDropZone
|
||||
{
|
||||
DropZone = dzToAddToFavorite,
|
||||
User = connectedUser
|
||||
};
|
||||
|
||||
var result = _favoriteDropZoneRepository.Add(favoriteDz);
|
||||
|
||||
return result > 0;
|
||||
return _cacheService.Get<IEnumerable<DropZone>>(CacheType.DropZone);
|
||||
}
|
||||
|
||||
public bool RemoveToFavorite(int dzId, User connectedUser)
|
||||
{
|
||||
var result = _favoriteDropZoneRepository.Delete(dzId, connectedUser.Id);
|
||||
#endregion Public Methods
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
#region Private Fields
|
||||
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly IDropZoneRepository _dropZoneRepository;
|
||||
|
||||
private readonly IFavoriteDropZoneRepository _favoriteDropZoneRepository;
|
||||
private readonly IIdentityService _identityService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class GearService : IGearService
|
||||
{
|
||||
public GearService(IGearRepository gearRepository)
|
||||
#region Public Constructors
|
||||
|
||||
public GearService(IGearRepository gearRepository,
|
||||
ICacheService cacheService,
|
||||
IIdentityService identityService)
|
||||
{
|
||||
_gearRepository = gearRepository;
|
||||
_cacheService = cacheService;
|
||||
_identityService = identityService;
|
||||
}
|
||||
|
||||
public void AddNewGear(Gear newGear,
|
||||
User connectedUser)
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddNewGear(Gear newGear)
|
||||
{
|
||||
newGear.User = connectedUser;
|
||||
newGear.User = _identityService.ConnectedUser;
|
||||
_gearRepository.Add(newGear);
|
||||
|
||||
var userId = _identityService.ConnectedUser.Id;
|
||||
_cacheService.Delete(CacheType.Gear, id: userId);
|
||||
}
|
||||
|
||||
public void AddRentalGear(User connectedUser)
|
||||
public void AddRentalGear(User newUser)
|
||||
{
|
||||
var rentalGear = new Gear
|
||||
{
|
||||
@@ -33,7 +44,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
MaxSize = 280,
|
||||
MinSize = 190,
|
||||
ReserveCanopy = "?",
|
||||
User = connectedUser
|
||||
User = newUser
|
||||
};
|
||||
|
||||
_gearRepository.Add(rentalGear);
|
||||
@@ -44,21 +55,39 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<Gear> GetAllGears()
|
||||
{
|
||||
var userId = _identityService.ConnectedUser.Id;
|
||||
if (!_cacheService.Contains(CacheType.Gear, id: userId))
|
||||
_cacheService.Put(CacheType.Gear,
|
||||
_gearRepository.GetAll(_identityService.ConnectedUser),
|
||||
5 * 60 * 1000,
|
||||
id: userId);
|
||||
|
||||
return _cacheService.Get<IEnumerable<Gear>>(CacheType.Gear, id: userId);
|
||||
}
|
||||
|
||||
public Gear GetGearById(int id)
|
||||
{
|
||||
return _gearRepository.GetById(id);
|
||||
var allGears = GetAllGears();
|
||||
return allGears.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
public IEnumerable<Gear> GetAllGears(User connectedUser)
|
||||
public bool UpdateGear(int id, Gear gear)
|
||||
{
|
||||
return _gearRepository.GetAll(connectedUser);
|
||||
gear.Id = id;
|
||||
|
||||
return _gearRepository.Update(gear);
|
||||
}
|
||||
|
||||
public void UpdateGear(int id, Gear Gear)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly IGearRepository _gearRepository;
|
||||
private readonly IIdentityService _identityService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Back/skydiveLogs-api.DomainBusiness/IdentityService.cs
Normal file
34
Back/skydiveLogs-api.DomainBusiness/IdentityService.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class IdentityService : IIdentityService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public IdentityService(ClaimsPrincipal user)
|
||||
{
|
||||
if (user != null
|
||||
&& user.Claims.Any())
|
||||
{
|
||||
var claims = user.Claims;
|
||||
|
||||
ConnectedUser = new User();
|
||||
ConnectedUser.Login = claims.Single(c => c.Type == ClaimTypes.Name).Value;
|
||||
ConnectedUser.Id = Convert.ToInt32(claims.Single(c => c.Type == ClaimTypes.UserData).Value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public User ConnectedUser { get; init; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class InitDbService : IInitDbService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public InitDbService(IAircraftService aircraftService,
|
||||
IJumpTypeService jumpTypeService,
|
||||
IDropZoneService dropZoneService,
|
||||
@@ -21,6 +21,10 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void GenerateDb()
|
||||
{
|
||||
LoadAircrafts();
|
||||
@@ -29,6 +33,39 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
AddAdmin();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void AddAdmin()
|
||||
{
|
||||
var adminUser = new User
|
||||
{
|
||||
FirstName = "Admin",
|
||||
LastName = "Admin",
|
||||
Login = "administrator",
|
||||
Password = "logsadmin",
|
||||
Email = "admin@nomail.com"
|
||||
};
|
||||
_userService.AddNewUser(adminUser, true);
|
||||
}
|
||||
|
||||
private void LoadAircrafts()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/aircraft.json");
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
var jsonModel = JsonSerializer.Deserialize<List<Aircraft>>(jsonString, options);
|
||||
|
||||
foreach (var item in jsonModel)
|
||||
{
|
||||
_aircraftService.AddNewAircraft(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadDropZones()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/dropZone.json");
|
||||
@@ -61,41 +98,16 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadAircrafts()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/aircraft.json");
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
var jsonModel = JsonSerializer.Deserialize<List<Aircraft>>(jsonString, options);
|
||||
#endregion Private Methods
|
||||
|
||||
foreach (var item in jsonModel)
|
||||
{
|
||||
_aircraftService.AddNewAircraft(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddAdmin()
|
||||
{
|
||||
var adminUser = new User
|
||||
{
|
||||
FirstName = "Admin",
|
||||
LastName = "Admin",
|
||||
Login = "administrator",
|
||||
Password = "logsadmin",
|
||||
Email = "admin@nomail.com"
|
||||
};
|
||||
_userService.AddNewUser(adminUser, true);
|
||||
}
|
||||
#region Private Fields
|
||||
|
||||
private readonly IAircraftService _aircraftService;
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
|
||||
private readonly IDropZoneService _dropZoneService;
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface ICacheService
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
bool Contains(CacheType type, int id = 0);
|
||||
|
||||
void Delete(CacheType type, int id = 0);
|
||||
|
||||
T Get<T>(CacheType type, int id = 0);
|
||||
|
||||
void Put(CacheType type, object value, int duration, int id = 0);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IDropZoneService
|
||||
{
|
||||
IEnumerable<DropZone> GetAllDzs(User connectedUser);
|
||||
|
||||
DropZone GetDzById(int id);
|
||||
|
||||
void DeleteDzById(int id);
|
||||
|
||||
bool UpdateDz(int id, DropZone dropZone);
|
||||
#region Public Methods
|
||||
|
||||
void AddNewDz(DropZone dropZone);
|
||||
|
||||
bool AddToFavorite(int dzId, User connectedUser);
|
||||
bool AddToFavorite(int dzId);
|
||||
|
||||
bool RemoveToFavorite(int dzId, User connectedUser);
|
||||
void DeleteDzById(int id);
|
||||
|
||||
IEnumerable<DropZone> GetAllDzs();
|
||||
|
||||
DropZone GetDzById(int id);
|
||||
|
||||
bool RemoveToFavorite(int dzId);
|
||||
|
||||
bool UpdateDz(int id, DropZone dropZone);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IGearService
|
||||
{
|
||||
IEnumerable<Gear> GetAllGears(User connectedUser);
|
||||
#region Public Methods
|
||||
|
||||
Gear GetGearById(int id);
|
||||
void AddNewGear(Gear gear);
|
||||
|
||||
void AddRentalGear(User newUser);
|
||||
|
||||
void DeleteGearById(int id);
|
||||
|
||||
void UpdateGear(int id, Gear gear);
|
||||
IEnumerable<Gear> GetAllGears();
|
||||
|
||||
void AddNewGear(Gear gear, User connectedUser);
|
||||
Gear GetGearById(int id);
|
||||
|
||||
void AddRentalGear(User connectedUser);
|
||||
bool UpdateGear(int id, Gear gear);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IIdentityService
|
||||
{
|
||||
User ConnectedUser { get; }
|
||||
}
|
||||
}
|
||||
@@ -2,24 +2,26 @@
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IJumpService
|
||||
{
|
||||
IEnumerable<Jump> GetAllJumps(User connectedUser);
|
||||
|
||||
Jump GetJumpById(int id);
|
||||
#region Public Methods
|
||||
|
||||
void AddNewJump(int aircraftId,
|
||||
int dzId,
|
||||
int jumpTypeId,
|
||||
int gearId,
|
||||
Jump jump,
|
||||
User connectedUser);
|
||||
Jump jump);
|
||||
|
||||
void DeleteJumpById(int id);
|
||||
|
||||
IEnumerable<Jump> GetAllJumps();
|
||||
|
||||
Jump GetJumpById(int id);
|
||||
|
||||
void UpdateJump(int id, Jump jump);
|
||||
|
||||
void DeleteJumpById(int id);
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IStatsService
|
||||
{
|
||||
IEnumerable<Statistic> GetStatsByDz(User connectedUser);
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStatsByAircraft(User connectedUser);
|
||||
SimpleSummary GetSimpleSummary();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByJumpType(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsByAircraft();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByGear(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsByDz();
|
||||
|
||||
IEnumerable<Statistic> GetStatsByYear(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsByGear();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByDz(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsByJumpType();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByJumpType(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsByYear();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByDz(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByDz();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByJumpType(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByJumpType();
|
||||
|
||||
SimpleSummary GetSimpleSummary(User connectedUser);
|
||||
IEnumerable<Statistic> GetStatsForLastYearByDz();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByJumpType();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,22 @@
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
public interface IUserImageService
|
||||
{
|
||||
IEnumerable<UserImage> GetAllImages(User connectedUser);
|
||||
#region Public Methods
|
||||
|
||||
void AddNewImage(UserImage image);
|
||||
|
||||
void DeleteImageById(int id);
|
||||
|
||||
IEnumerable<UserImage> GetAllImages();
|
||||
|
||||
UserImage GetImageById(int id);
|
||||
|
||||
void AddNewImage(UserImage image, User connectedUser);
|
||||
|
||||
void UpdateImage(int id, UserImage image);
|
||||
|
||||
void DeleteImageById(int id);
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class JumpService : IJumpService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public JumpService(IJumpTypeService jumpTypeService,
|
||||
IAircraftService aircraftService,
|
||||
IDropZoneService dropZoneService,
|
||||
IGearService gearService,
|
||||
IJumpRepository jumpRepository)
|
||||
IJumpRepository jumpRepository,
|
||||
IIdentityService identityService)
|
||||
{
|
||||
_jumpTypeService = jumpTypeService;
|
||||
_aircraftService = aircraftService;
|
||||
_dropZoneService = dropZoneService;
|
||||
_gearService = gearService;
|
||||
_jumpRepository = jumpRepository;
|
||||
_identityService = identityService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddNewJump(int aircraftId,
|
||||
int dzId,
|
||||
int jumpTypeId,
|
||||
int gearId,
|
||||
Jump jump,
|
||||
User connectedUser)
|
||||
Jump jump)
|
||||
{
|
||||
var selectedGear = _gearService.GetGearById(gearId);
|
||||
var selectedJumpType = _jumpTypeService.GetJumpTypeById(jumpTypeId);
|
||||
@@ -39,7 +44,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
jump.JumpType = selectedJumpType;
|
||||
jump.DropZone = selectedDropZone;
|
||||
jump.Gear = selectedGear;
|
||||
jump.User = connectedUser;
|
||||
jump.User = _identityService.ConnectedUser;
|
||||
|
||||
_jumpRepository.Add(jump);
|
||||
}
|
||||
@@ -49,9 +54,9 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<Jump> GetAllJumps(User connectedUser)
|
||||
public IEnumerable<Jump> GetAllJumps()
|
||||
{
|
||||
return _jumpRepository.GetAll(connectedUser);
|
||||
return _jumpRepository.GetAll(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
public Jump GetJumpById(int id)
|
||||
@@ -64,14 +69,17 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IJumpRepository _jumpRepository;
|
||||
#endregion Public Methods
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
#region Private Fields
|
||||
|
||||
private readonly IAircraftService _aircraftService;
|
||||
|
||||
private readonly IDropZoneService _dropZoneService;
|
||||
|
||||
private readonly IGearService _gearService;
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpRepository _jumpRepository;
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class JumpTypeService : IJumpTypeService
|
||||
{
|
||||
public JumpTypeService(IJumpTypeRepository jumpTypeRepository)
|
||||
#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)
|
||||
@@ -27,12 +35,18 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
public IEnumerable<JumpType> GetAllJumpTypes()
|
||||
{
|
||||
return _jumpTypeRepository.GetAll();
|
||||
if (!_cacheService.Contains(CacheType.JumpType))
|
||||
_cacheService.Put(CacheType.JumpType,
|
||||
_jumpTypeRepository.GetAll(),
|
||||
5 * 60 * 1000);
|
||||
|
||||
return _cacheService.Get<IEnumerable<JumpType>>(CacheType.JumpType);
|
||||
}
|
||||
|
||||
public JumpType GetJumpTypeById(int id)
|
||||
{
|
||||
return _jumpTypeRepository.GetById(id);
|
||||
var allJumpTypes = GetAllJumpTypes();
|
||||
return allJumpTypes.Single(g => g.Id == id);
|
||||
}
|
||||
|
||||
public void UpdateJumpType(int id, JumpType value)
|
||||
@@ -40,6 +54,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly IJumpTypeRepository _jumpTypeRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,220 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class StatsService : IStatsService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public StatsService(IJumpService jumpService)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByAircraft(User connectedUser)
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public SimpleSummary GetSimpleSummary()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.Gear.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||
.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
|
||||
.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public SimpleSummary GetSimpleSummary(User connectedUser)
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps(connectedUser);
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new SimpleSummary();
|
||||
|
||||
if (allJumps.Any())
|
||||
@@ -232,6 +38,210 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.Gear.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
|
||||
.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||
.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
|
||||
results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
|
||||
.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IJumpService _jumpService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class UserImageService : IUserImageService
|
||||
{
|
||||
public UserImageService(IUserImageRepository imageRepository)
|
||||
#region Public Constructors
|
||||
|
||||
public UserImageService(IUserImageRepository imageRepository,
|
||||
IIdentityService identityService)
|
||||
{
|
||||
_imageRepository = imageRepository;
|
||||
_identityService = identityService;
|
||||
}
|
||||
|
||||
public void AddNewImage(UserImage newImage, User connectedUser)
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void AddNewImage(UserImage newImage)
|
||||
{
|
||||
newImage.User = connectedUser;
|
||||
newImage.User = _identityService.ConnectedUser;
|
||||
_imageRepository.Add(newImage);
|
||||
}
|
||||
|
||||
@@ -26,21 +32,28 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<UserImage> GetAllImages()
|
||||
{
|
||||
return _imageRepository.GetAll(_identityService.ConnectedUser);
|
||||
}
|
||||
|
||||
public UserImage GetImageById(int id)
|
||||
{
|
||||
return _imageRepository.GetById(id);
|
||||
}
|
||||
|
||||
public IEnumerable<UserImage> GetAllImages(User connectedUser)
|
||||
{
|
||||
return _imageRepository.GetAll(connectedUser);
|
||||
}
|
||||
|
||||
public void UpdateImage(int id, UserImage Image)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IUserImageRepository _imageRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class UserService : IUserService
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public UserService(IUserRepository userRepository,
|
||||
IGearService gearService)
|
||||
{
|
||||
@@ -19,15 +19,9 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
_gearService = gearService;
|
||||
}
|
||||
|
||||
public User GetById(int userId)
|
||||
{
|
||||
return _userRepository.GetById(userId);
|
||||
}
|
||||
#endregion Public Constructors
|
||||
|
||||
public User GetByLogin(string login, string password)
|
||||
{
|
||||
return _userRepository.GetByLogin(login, EncryptPassword(password));
|
||||
}
|
||||
#region Public Methods
|
||||
|
||||
public bool AddNewUser(User newUser, bool isAdmin = false)
|
||||
{
|
||||
@@ -51,9 +45,23 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return result;
|
||||
}
|
||||
|
||||
public User GetById(int userId)
|
||||
{
|
||||
return _userRepository.GetById(userId);
|
||||
}
|
||||
|
||||
public User GetByLogin(string login, string password)
|
||||
{
|
||||
return _userRepository.GetByLogin(login, EncryptPassword(password));
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string EncryptPassword(string password)
|
||||
{
|
||||
var encryptionKey = "skydivelogsangular"; //we can change the code converstion key as per our requirement
|
||||
var encryptionKey = "skydivelogsangular"; //we can change the code converstion key as per our requirement
|
||||
byte[] clearBytes = Encoding.Unicode.GetBytes(password);
|
||||
var encryptedPassword = string.Empty;
|
||||
|
||||
@@ -78,8 +86,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return encryptedPassword;
|
||||
}
|
||||
|
||||
private readonly IUserRepository _userRepository;
|
||||
#endregion Private Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IGearService _gearService;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@
|
||||
<RootNamespace>skydiveLogs_api.DomainBusiness</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Runtime.Caching" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\skydiveLogs-api.DomainService\skydiveLogs-api.DomainService.csproj" />
|
||||
<ProjectReference Include="..\skydiveLogs-api.Domain\skydiveLogs-api.Domain.csproj" />
|
||||
|
||||
Reference in New Issue
Block a user