Store the user statistics for the performance.
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Business.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class AircraftService : IAircraftService
|
||||
{
|
||||
public AircraftService(IAircraftRepository aircraftRepository)
|
||||
{
|
||||
_aircraftRepository = aircraftRepository;
|
||||
}
|
||||
|
||||
public void AddNewAircraft(Aircraft newAircraft)
|
||||
{
|
||||
_aircraftRepository.Add(newAircraft);
|
||||
}
|
||||
|
||||
public void DeleteAircraftById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Aircraft GetAircraftById(int id)
|
||||
{
|
||||
return _aircraftRepository.GetById(id);
|
||||
}
|
||||
|
||||
public IEnumerable<Aircraft> GetAllAircrafts()
|
||||
{
|
||||
return _aircraftRepository.GetAll();
|
||||
}
|
||||
|
||||
public void UpdateAircraft(int id, Aircraft aircraft)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IAircraftRepository _aircraftRepository;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Business.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class DropZoneService : IDropZoneService
|
||||
{
|
||||
public DropZoneService(IDropZoneRepository dropZoneRepository)
|
||||
{
|
||||
_dropZoneRepository = dropZoneRepository;
|
||||
}
|
||||
|
||||
public void AddNewDz(DropZone newdropZone)
|
||||
{
|
||||
_dropZoneRepository.Add(newdropZone);
|
||||
}
|
||||
|
||||
public void DeleteDzById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<DropZone> GetAllDzs()
|
||||
{
|
||||
return _dropZoneRepository.GetAll();
|
||||
}
|
||||
|
||||
public DropZone GetDzById(int id)
|
||||
{
|
||||
return _dropZoneRepository.GetById(id);
|
||||
}
|
||||
|
||||
public bool UpdateDz(int id, DropZone dropZone)
|
||||
{
|
||||
dropZone.Id = id;
|
||||
|
||||
return _dropZoneRepository.Update(dropZone);
|
||||
}
|
||||
|
||||
private readonly IDropZoneRepository _dropZoneRepository;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Business.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class GearService : IGearService
|
||||
{
|
||||
public GearService(IGearRepository gearRepository)
|
||||
{
|
||||
_gearRepository = gearRepository;
|
||||
}
|
||||
|
||||
public void AddNewGear(Gear newGear,
|
||||
User connectedUser)
|
||||
{
|
||||
newGear.User = connectedUser;
|
||||
_gearRepository.Add(newGear);
|
||||
}
|
||||
|
||||
public void DeleteGearById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Gear GetGearById(int id)
|
||||
{
|
||||
return _gearRepository.GetById(id);
|
||||
}
|
||||
|
||||
public IEnumerable<Gear> GetAllGears(User connectedUser)
|
||||
{
|
||||
return _gearRepository.GetAll(connectedUser);
|
||||
}
|
||||
|
||||
public void UpdateGear(int id, Gear Gear)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IGearRepository _gearRepository;
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
using skydiveLogs_api.Business.Interfaces;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class InitDbService : IInitDbService
|
||||
{
|
||||
public InitDbService(IAircraftService aircraftService,
|
||||
IJumpTypeService jumpTypeService,
|
||||
IDropZoneService dropZoneService)
|
||||
{
|
||||
_aircraftService = aircraftService;
|
||||
_jumpTypeService = jumpTypeService;
|
||||
_dropZoneService = dropZoneService;
|
||||
}
|
||||
|
||||
public void GenerateDb()
|
||||
{
|
||||
LoadAircrafts();
|
||||
LoadDropZones();
|
||||
LoadJumpTypes();
|
||||
}
|
||||
|
||||
private void LoadDropZones()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/dropZone.json");
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
var jsonModel = JsonSerializer.Deserialize<List<DropZone>>(jsonString, options);
|
||||
|
||||
foreach (var item in jsonModel)
|
||||
{
|
||||
_dropZoneService.AddNewDz(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadJumpTypes()
|
||||
{
|
||||
var jsonString = File.ReadAllText("Init/jumpType.json");
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
var jsonModel = JsonSerializer.Deserialize<List<JumpType>>(jsonString, options);
|
||||
|
||||
foreach (var item in jsonModel)
|
||||
{
|
||||
_jumpTypeService.AddNewJumpType(item);
|
||||
}
|
||||
}
|
||||
|
||||
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 readonly IAircraftService _aircraftService;
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
|
||||
private readonly IDropZoneService _dropZoneService;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interfaces
|
||||
{
|
||||
public interface IAircraftService
|
||||
{
|
||||
IEnumerable<Aircraft> GetAllAircrafts();
|
||||
|
||||
Aircraft GetAircraftById(int id);
|
||||
|
||||
void AddNewAircraft(Aircraft aircraft);
|
||||
|
||||
void UpdateAircraft(int id, Aircraft aircraft);
|
||||
|
||||
void DeleteAircraftById(int id);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interfaces
|
||||
{
|
||||
public interface IDropZoneService
|
||||
{
|
||||
IEnumerable<DropZone> GetAllDzs();
|
||||
|
||||
DropZone GetDzById(int id);
|
||||
|
||||
void DeleteDzById(int id);
|
||||
|
||||
bool UpdateDz(int id, DropZone dropZone);
|
||||
|
||||
void AddNewDz(DropZone dropZone);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interfaces
|
||||
{
|
||||
public interface IGearService
|
||||
{
|
||||
IEnumerable<Gear> GetAllGears(User connectedUser);
|
||||
|
||||
Gear GetGearById(int id);
|
||||
|
||||
void DeleteGearById(int id);
|
||||
|
||||
void UpdateGear(int id, Gear gear);
|
||||
|
||||
void AddNewGear(Gear gear, User connectedUser);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace skydiveLogs_api.Business.Interfaces
|
||||
{
|
||||
public interface IInitDbService
|
||||
{
|
||||
public void GenerateDb();
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interfaces
|
||||
{
|
||||
public interface IJumpService
|
||||
{
|
||||
IEnumerable<Jump> GetAllJumps(User connectedUser);
|
||||
|
||||
Jump GetJumpById(int id);
|
||||
|
||||
void AddNewJump(int aircraftId,
|
||||
int dzId,
|
||||
int jumpTypeId,
|
||||
int gearId,
|
||||
Jump jump,
|
||||
User connectedUser);
|
||||
|
||||
void UpdateJump(int id, Jump jump);
|
||||
|
||||
void DeleteJumpById(int id);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interfaces
|
||||
{
|
||||
public interface IJumpTypeService
|
||||
{
|
||||
IEnumerable<JumpType> GetAllJumpTypes();
|
||||
|
||||
JumpType GetJumpTypeById(int id);
|
||||
|
||||
void AddNewJumpType(JumpType value);
|
||||
|
||||
void UpdateJumpType(int id, JumpType value);
|
||||
|
||||
void DeleteJumpTypeById(int id);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interfaces
|
||||
{
|
||||
public interface IStatsService
|
||||
{
|
||||
IEnumerable<Statistic> GetStatsByDz(User connectedUser);
|
||||
|
||||
IEnumerable<Statistic> GetStatsByAircraft(User connectedUser);
|
||||
|
||||
IEnumerable<Statistic> GetStatsByJumpType(User connectedUser);
|
||||
|
||||
IEnumerable<Statistic> GetStatsByGear(User connectedUser);
|
||||
|
||||
IEnumerable<Statistic> GetStatsByYear(User connectedUser);
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByDz(User connectedUser);
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByJumpType(User connectedUser);
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByDz(User connectedUser);
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastMonthByJumpType(User connectedUser);
|
||||
|
||||
SimpleSummary GetSimpleSummary(User connectedUser);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interfaces
|
||||
{
|
||||
public interface IUserImageService
|
||||
{
|
||||
IEnumerable<UserImage> GetAllImages(User connectedUser);
|
||||
|
||||
UserImage GetImageById(int id);
|
||||
|
||||
void AddNewImage(UserImage image, User connectedUser);
|
||||
|
||||
void UpdateImage(int id, UserImage image);
|
||||
|
||||
void DeleteImageById(int id);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.Business.Interfaces
|
||||
{
|
||||
public interface IUserService
|
||||
{
|
||||
User GetByLogin(string login, string password);
|
||||
|
||||
User GetById(int userId);
|
||||
|
||||
bool AddNewUser(User user);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Business.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class JumpService : IJumpService
|
||||
{
|
||||
public JumpService(IJumpTypeService jumpTypeService,
|
||||
IAircraftService aircraftService,
|
||||
IDropZoneService dropZoneService,
|
||||
IGearService gearService,
|
||||
IJumpRepository jumpRepository)
|
||||
{
|
||||
_jumpTypeService = jumpTypeService;
|
||||
_aircraftService = aircraftService;
|
||||
_dropZoneService = dropZoneService;
|
||||
_gearService = gearService;
|
||||
_jumpRepository = jumpRepository;
|
||||
}
|
||||
|
||||
public void AddNewJump(int aircraftId,
|
||||
int dzId,
|
||||
int jumpTypeId,
|
||||
int gearId,
|
||||
Jump jump,
|
||||
User connectedUser)
|
||||
{
|
||||
var selectedGear = _gearService.GetGearById(gearId);
|
||||
var selectedJumpType = _jumpTypeService.GetJumpTypeById(jumpTypeId);
|
||||
var selectedAircraft = _aircraftService.GetAircraftById(aircraftId);
|
||||
var selectedDropZone = _dropZoneService.GetDzById(dzId);
|
||||
|
||||
jump.Aircraft = selectedAircraft;
|
||||
jump.JumpType = selectedJumpType;
|
||||
jump.DropZone = selectedDropZone;
|
||||
jump.Gear = selectedGear;
|
||||
jump.User = connectedUser;
|
||||
|
||||
_jumpRepository.Add(jump);
|
||||
}
|
||||
|
||||
public void DeleteJumpById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<Jump> GetAllJumps(User connectedUser)
|
||||
{
|
||||
return _jumpRepository.GetAll(connectedUser);
|
||||
}
|
||||
|
||||
public Jump GetJumpById(int id)
|
||||
{
|
||||
return _jumpRepository.GetById(id);
|
||||
}
|
||||
|
||||
public void UpdateJump(int id, Jump jump)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IJumpRepository _jumpRepository;
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
|
||||
private readonly IAircraftService _aircraftService;
|
||||
|
||||
private readonly IDropZoneService _dropZoneService;
|
||||
|
||||
private readonly IGearService _gearService;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Business.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class JumpTypeService : IJumpTypeService
|
||||
{
|
||||
public JumpTypeService(IJumpTypeRepository jumpTypeRepository)
|
||||
{
|
||||
_jumpTypeRepository = jumpTypeRepository;
|
||||
}
|
||||
|
||||
public void AddNewJumpType(JumpType newJumpType)
|
||||
{
|
||||
_jumpTypeRepository.Add(newJumpType);
|
||||
}
|
||||
|
||||
public void DeleteJumpTypeById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<JumpType> GetAllJumpTypes()
|
||||
{
|
||||
return _jumpTypeRepository.GetAll();
|
||||
}
|
||||
|
||||
public JumpType GetJumpTypeById(int id)
|
||||
{
|
||||
return _jumpTypeRepository.GetById(id);
|
||||
}
|
||||
|
||||
public void UpdateJumpType(int id, JumpType value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IJumpTypeRepository _jumpTypeRepository;
|
||||
}
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using skydiveLogs_api.Business.Interfaces;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class StatsService : IStatsService
|
||||
{
|
||||
public StatsService(IJumpService jumpService)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByAircraft(User connectedUser)
|
||||
{
|
||||
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 results = new SimpleSummary();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
|
||||
results = new SimpleSummary
|
||||
{
|
||||
LastJump = lastJump,
|
||||
TotalJumps = allJumps.Count(),
|
||||
TotalCutaways = allJumps.Where(j => j.WithCutaway).Count()
|
||||
};
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private readonly IJumpService _jumpService;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Business.Interfaces;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class UserImageService : IUserImageService
|
||||
{
|
||||
public UserImageService(IUserImageRepository imageRepository)
|
||||
{
|
||||
_imageRepository = imageRepository;
|
||||
}
|
||||
|
||||
public void AddNewImage(UserImage newImage, User connectedUser)
|
||||
{
|
||||
newImage.User = connectedUser;
|
||||
_imageRepository.Add(newImage);
|
||||
}
|
||||
|
||||
public void DeleteImageById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private readonly IUserImageRepository _imageRepository;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
using skydiveLogs_api.Business.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class UserService : IUserService
|
||||
{
|
||||
public UserService(IUserRepository userRepository)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
public User GetById(int userId)
|
||||
{
|
||||
return _userRepository.GetById(userId);
|
||||
}
|
||||
|
||||
public User GetByLogin(string login, string password)
|
||||
{
|
||||
return _userRepository.GetByLogin(login, EncryptPassword(password));
|
||||
}
|
||||
|
||||
public bool AddNewUser(User newUser)
|
||||
{
|
||||
newUser.Password = EncryptPassword(newUser.Password);
|
||||
var foundUser = _userRepository.GetByLogin(newUser.Login, newUser.Password);
|
||||
var result = false;
|
||||
|
||||
if (foundUser == null)
|
||||
{
|
||||
_userRepository.Add(newUser);
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private string EncryptPassword(string password)
|
||||
{
|
||||
var encryptionKey = "skydivelogsangular"; //we can change the code converstion key as per our requirement
|
||||
byte[] clearBytes = Encoding.Unicode.GetBytes(password);
|
||||
var encryptedPassword = string.Empty;
|
||||
|
||||
using (Aes encryptor = Aes.Create())
|
||||
{
|
||||
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(encryptionKey,
|
||||
new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
|
||||
encryptor.Key = pdb.GetBytes(32);
|
||||
encryptor.IV = pdb.GetBytes(16);
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
|
||||
{
|
||||
cs.Write(clearBytes, 0, clearBytes.Length);
|
||||
cs.Close();
|
||||
}
|
||||
|
||||
encryptedPassword = Convert.ToBase64String(ms.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
return encryptedPassword;
|
||||
}
|
||||
|
||||
private readonly IUserRepository _userRepository;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<RootNamespace>skydiveLogs_api.Business</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\skydiveLogs-api.DomainService\skydiveLogs-api.DomainService.csproj" />
|
||||
<ProjectReference Include="..\skydiveLogs-api.Model\skydiveLogs-api.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,56 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class AircraftRepository : IAircraftRepository
|
||||
{
|
||||
public AircraftRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Aircraft> GetAll()
|
||||
{
|
||||
return _col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public Aircraft GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
public bool Update(Aircraft aircraft)
|
||||
{
|
||||
return _col.Update(aircraft);
|
||||
}
|
||||
|
||||
public bool Add(Aircraft newAircraft)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
try
|
||||
{
|
||||
_col.Insert(newAircraft);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly ILiteCollection<Aircraft> _col;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class DropZoneRepository : IDropZoneRepository
|
||||
{
|
||||
public DropZoneRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfDropZone;
|
||||
}
|
||||
|
||||
public IEnumerable<DropZone> GetAll()
|
||||
{
|
||||
return _col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public DropZone GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
public bool Update(DropZone updatedDz)
|
||||
{
|
||||
return _col.Update(updatedDz);
|
||||
}
|
||||
|
||||
public bool Add(DropZone newDz)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
try
|
||||
{
|
||||
_col.Insert(newDz);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly ILiteCollection<DropZone> _col;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class GearRepository : IGearRepository
|
||||
{
|
||||
public GearRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Gear> GetAll()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<Gear> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public Gear GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
public bool Update(Gear updatedGear)
|
||||
{
|
||||
return _col.Update(updatedGear);
|
||||
}
|
||||
|
||||
public bool Add(Gear newGear)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
try
|
||||
{
|
||||
_col.Insert(newGear);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly ILiteCollection<Gear> _col;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure.Interfaces
|
||||
{
|
||||
public interface IDataProvider
|
||||
{
|
||||
ILiteCollection<T> GetCollection<T>();
|
||||
|
||||
void Close();
|
||||
|
||||
ILiteCollection<Aircraft> CollOfAircraft { get; }
|
||||
|
||||
ILiteCollection<DropZone> CollOfDropZone { get; }
|
||||
|
||||
ILiteCollection<Gear> CollOfGear { get; }
|
||||
|
||||
ILiteCollection<JumpType> CollOfJumpType { get; }
|
||||
|
||||
ILiteCollection<Jump> CollOfJump { get; }
|
||||
|
||||
ILiteCollection<User> CollOfUser { get; }
|
||||
|
||||
ILiteCollection<UserImage> CollOfImage { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class JumpRepository : IJumpRepository
|
||||
{
|
||||
public JumpRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfJump;
|
||||
}
|
||||
|
||||
public IEnumerable<Jump> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.Aircraft)
|
||||
.Include(x => x.DropZone)
|
||||
.Include(x => x.Gear)
|
||||
.Include(x => x.JumpType)
|
||||
.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public Jump GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
public bool Add(Jump newJump)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
try
|
||||
{
|
||||
_col.Insert(newJump);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool Update(Jump updatedJump)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<Jump> GetAll()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly ILiteCollection<Jump> _col;
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class JumpTypeRepository : IJumpTypeRepository
|
||||
{
|
||||
public JumpTypeRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<JumpType> GetAll()
|
||||
{
|
||||
return _col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public JumpType GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
public bool Update(JumpType updatedJumpType)
|
||||
{
|
||||
return _col.Update(updatedJumpType);
|
||||
}
|
||||
|
||||
public bool Add(JumpType newJumpType)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
try
|
||||
{
|
||||
_col.Insert(newJumpType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly ILiteCollection<JumpType> _col;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class LiteDbProvider : IDataProvider
|
||||
{
|
||||
public LiteDbProvider(string connectionString)
|
||||
{
|
||||
_db = new LiteDatabase(connectionString);
|
||||
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.JumpType, "JumpType");
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Aircraft, "Aircraft");
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.DropZone, "DropZone");
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Gear, "Gear");
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.User, "User");
|
||||
|
||||
BsonMapper.Global.Entity<UserImage>().DbRef(x => x.User, "User");
|
||||
|
||||
BsonMapper.Global.Entity<Gear>().DbRef(x => x.User, "User");
|
||||
}
|
||||
|
||||
public ILiteCollection<T> GetCollection<T>()
|
||||
{
|
||||
return _db.GetCollection<T>();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_db.Dispose();
|
||||
}
|
||||
|
||||
private readonly LiteDatabase _db;
|
||||
|
||||
public ILiteCollection<Aircraft> CollOfAircraft => _db.GetCollection<Aircraft>();
|
||||
|
||||
public ILiteCollection<DropZone> CollOfDropZone => _db.GetCollection<DropZone>();
|
||||
|
||||
public ILiteCollection<Gear> CollOfGear => _db.GetCollection<Gear>();
|
||||
|
||||
public ILiteCollection<JumpType> CollOfJumpType => _db.GetCollection<JumpType>();
|
||||
|
||||
public ILiteCollection<Jump> CollOfJump => _db.GetCollection<Jump>();
|
||||
|
||||
public ILiteCollection<User> CollOfUser => _db.GetCollection<User>();
|
||||
|
||||
public ILiteCollection<UserImage> CollOfImage => _db.GetCollection<UserImage>();
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class UserImageRepository : IUserImageRepository
|
||||
{
|
||||
public UserImageRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfImage;
|
||||
}
|
||||
|
||||
public IEnumerable<UserImage> GetAll()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<UserImage> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User == user)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public UserImage GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
public bool Update(UserImage image)
|
||||
{
|
||||
return _col.Update(image);
|
||||
}
|
||||
|
||||
public bool Add(UserImage newImage)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
try
|
||||
{
|
||||
_col.Insert(newImage);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly ILiteCollection<UserImage> _col;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class UserRepository : IUserRepository
|
||||
{
|
||||
public UserRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfUser;
|
||||
}
|
||||
|
||||
public User GetByLogin(string login, string password)
|
||||
{
|
||||
return _col.FindOne(u => u.Login == login && u.Password == password);
|
||||
}
|
||||
|
||||
public bool Add(User newUser)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
try
|
||||
{
|
||||
_col.Insert(newUser);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<User> GetAll()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public User GetById(int id)
|
||||
{
|
||||
return _col.FindById(new BsonValue(id));
|
||||
}
|
||||
|
||||
public bool Update(User updated)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly ILiteCollection<User> _col;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<RootNamespace>skydiveLogs_api.Infrastructure</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteDB" Version="5.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\skydiveLogs-api.DomainService\skydiveLogs-api.DomainService.csproj" />
|
||||
<ProjectReference Include="..\skydiveLogs-api.Model\skydiveLogs-api.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -2,10 +2,13 @@
|
||||
{
|
||||
public class Aircraft
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public string ImageData { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public string ImageData { get; set; }
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
{
|
||||
public class DatabaseOptions
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public string ConnectionString { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,22 +4,21 @@ namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class DropZone
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public string Address { get; set; }
|
||||
public string Email { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Latitude { get; set; }
|
||||
public bool IsFavorite { get; set; }
|
||||
public string Latitude { get; set; }
|
||||
|
||||
public string Longitude { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Address { get; set; }
|
||||
|
||||
public IEnumerable<string> Type { get; set; }
|
||||
public string Website { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public IEnumerable<string> Type { get; set; }
|
||||
|
||||
public bool IsFavorite { get; set; }
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,12 @@
|
||||
{
|
||||
public class FavoriteDropZone
|
||||
{
|
||||
public int Id { get; set; }
|
||||
#region Public Properties
|
||||
|
||||
public DropZone DropZone { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,22 +2,20 @@
|
||||
{
|
||||
public class Gear
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Manufacturer { get; set; }
|
||||
|
||||
public int MinSize { get; set; }
|
||||
|
||||
public int MaxSize { get; set; }
|
||||
#region Public Properties
|
||||
|
||||
public string Aad { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public string MainCanopy { get; set; }
|
||||
|
||||
public string Manufacturer { get; set; }
|
||||
public int MaxSize { get; set; }
|
||||
public int MinSize { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ReserveCanopy { get; set; }
|
||||
|
||||
public User User { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,28 +4,22 @@ namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class Jump
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public JumpType JumpType { get; set; }
|
||||
#region Public Properties
|
||||
|
||||
public Aircraft Aircraft { get; set; }
|
||||
|
||||
public DropZone DropZone { get; set; }
|
||||
|
||||
public Gear Gear { get; set; }
|
||||
|
||||
public User User { get; set; }
|
||||
|
||||
public int ExitAltitude { get; set; }
|
||||
|
||||
public int DeployAltitude { get; set; }
|
||||
|
||||
public bool WithCutaway { get; set; }
|
||||
|
||||
public string Notes { get; set; }
|
||||
|
||||
public DateTime JumpDate { get; set; }
|
||||
public DropZone DropZone { get; set; }
|
||||
public int ExitAltitude { get; set; }
|
||||
public Gear Gear { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public bool IsSpecial { get; set; }
|
||||
public DateTime JumpDate { get; set; }
|
||||
public JumpType JumpType { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public User User { get; set; }
|
||||
public bool WithCutaway { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,12 @@
|
||||
{
|
||||
public class JumpType
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,12 @@
|
||||
{
|
||||
public class SimpleSummary
|
||||
{
|
||||
public int TotalJumps { get; set; }
|
||||
|
||||
public int TotalCutaways { get; set; }
|
||||
#region Public Properties
|
||||
|
||||
public Jump LastJump { get; set; }
|
||||
public int TotalCutaways { get; set; }
|
||||
public int TotalJumps { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,12 @@
|
||||
{
|
||||
public class Statistic
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public string Label { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,20 +2,19 @@
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public int Id { get; set; }
|
||||
#region Public Properties
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
public bool IsAdmin { get; set; }
|
||||
public string Language { get; set; }
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string Login { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public bool IsAdmin { get; set; }
|
||||
|
||||
public string Language { get; set; }
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,13 @@
|
||||
{
|
||||
public class UserImage
|
||||
{
|
||||
public int Id { get; set; }
|
||||
#region Public Properties
|
||||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string Data { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Back/skydiveLogs-api.Domain/UserStats.cs
Normal file
40
Back/skydiveLogs-api.Domain/UserStats.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class UserStats
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public UserStats()
|
||||
{
|
||||
ByAircraft = new List<Statistic>();
|
||||
ByDz = new List<Statistic>();
|
||||
ByGear = new List<Statistic>();
|
||||
ByJumpType = new List<Statistic>();
|
||||
ByYear = new List<Statistic>();
|
||||
ForLastMonthByDz = new List<Statistic>();
|
||||
ForLastMonthByJumpType = new List<Statistic>();
|
||||
ForLastYearByDz = new List<Statistic>();
|
||||
ForLastYearByJumpType = new List<Statistic>();
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public IEnumerable<Statistic> ByAircraft { get; set; }
|
||||
public IEnumerable<Statistic> ByDz { get; set; }
|
||||
public IEnumerable<Statistic> ByGear { get; set; }
|
||||
public IEnumerable<Statistic> ByJumpType { get; set; }
|
||||
public IEnumerable<Statistic> ByYear { get; set; }
|
||||
public IEnumerable<Statistic> ForLastMonthByDz { get; set; }
|
||||
public IEnumerable<Statistic> ForLastMonthByJumpType { get; set; }
|
||||
public IEnumerable<Statistic> ForLastYearByDz { get; set; }
|
||||
public IEnumerable<Statistic> ForLastYearByJumpType { get; set; }
|
||||
public int Id { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -9,27 +9,27 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
public bool Contains(CacheType type, int id = 0)
|
||||
public bool Contains(CacheType type, int userId = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
var key = GetKey(userId, type);
|
||||
return MemoryCache.Default[key.ToString()] != null;
|
||||
}
|
||||
|
||||
public void Delete(CacheType type, int id = 0)
|
||||
public void Delete(CacheType type, int userId = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
var key = GetKey(userId, type);
|
||||
MemoryCache.Default.Remove(key.ToString());
|
||||
}
|
||||
|
||||
public T Get<T>(CacheType type, int id = 0)
|
||||
public T Get<T>(CacheType type, int userId = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
var key = GetKey(userId, type);
|
||||
return (T)MemoryCache.Default[key.ToString()];
|
||||
}
|
||||
|
||||
public void Put(CacheType type, object value, int duration, int id = 0)
|
||||
public void Put(CacheType type, object value, int duration, int userId = 0)
|
||||
{
|
||||
var key = GetKey(id, type);
|
||||
var key = GetKey(userId, type);
|
||||
if (duration <= 0)
|
||||
throw new ArgumentException("Duration cannot be less or equal to zero", "duration");
|
||||
|
||||
@@ -41,9 +41,9 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
MemoryCache.Default.Set(key.ToString(), value, policy);
|
||||
}
|
||||
|
||||
private string GetKey(int id, CacheType type)
|
||||
private string GetKey(int userId, CacheType type)
|
||||
{
|
||||
return $"{id}-{type}";
|
||||
return $"{userId}-{type}";
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
_gearRepository.Add(newGear);
|
||||
|
||||
var userId = _identityService.ConnectedUser.Id;
|
||||
_cacheService.Delete(CacheType.Gear, id: userId);
|
||||
_cacheService.Delete(CacheType.Gear, userId: userId);
|
||||
}
|
||||
|
||||
public void AddRentalGear(User newUser)
|
||||
@@ -58,13 +58,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
public IEnumerable<Gear> GetAllGears()
|
||||
{
|
||||
var userId = _identityService.ConnectedUser.Id;
|
||||
if (!_cacheService.Contains(CacheType.Gear, id: userId))
|
||||
if (!_cacheService.Contains(CacheType.Gear, userId: userId))
|
||||
_cacheService.Put(CacheType.Gear,
|
||||
_gearRepository.GetAll(_identityService.ConnectedUser),
|
||||
5 * 60 * 1000,
|
||||
id: userId);
|
||||
userId: userId);
|
||||
|
||||
return _cacheService.Get<IEnumerable<Gear>>(CacheType.Gear, id: userId);
|
||||
return _cacheService.Get<IEnumerable<Gear>>(CacheType.Gear, userId: userId);
|
||||
}
|
||||
|
||||
public Gear GetGearById(int id)
|
||||
|
||||
@@ -6,13 +6,13 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
bool Contains(CacheType type, int id = 0);
|
||||
bool Contains(CacheType type, int userId = 0);
|
||||
|
||||
void Delete(CacheType type, int id = 0);
|
||||
void Delete(CacheType type, int userId = 0);
|
||||
|
||||
T Get<T>(CacheType type, int id = 0);
|
||||
T Get<T>(CacheType type, int userId = 0);
|
||||
|
||||
void Put(CacheType type, object value, int duration, int id = 0);
|
||||
void Put(CacheType type, object value, int duration, int userId = 0);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
IEnumerable<Statistic> GetStatsForLastYearByDz();
|
||||
|
||||
IEnumerable<Statistic> GetStatsForLastYearByJumpType();
|
||||
void Reset();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
IDropZoneService dropZoneService,
|
||||
IGearService gearService,
|
||||
IJumpRepository jumpRepository,
|
||||
IIdentityService identityService)
|
||||
IIdentityService identityService,
|
||||
IStatsService statsService)
|
||||
{
|
||||
_jumpTypeService = jumpTypeService;
|
||||
_aircraftService = aircraftService;
|
||||
@@ -22,6 +23,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
_gearService = gearService;
|
||||
_jumpRepository = jumpRepository;
|
||||
_identityService = identityService;
|
||||
_statsService = statsService;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
@@ -46,11 +48,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
jump.User = _identityService.ConnectedUser;
|
||||
|
||||
_jumpRepository.Add(jump);
|
||||
_statsService.Reset();
|
||||
}
|
||||
|
||||
public void DeleteJumpById(int id)
|
||||
{
|
||||
_jumpRepository.DeleteById(id);
|
||||
_statsService.Reset();
|
||||
}
|
||||
|
||||
public IEnumerable<Jump> GetAllJumps()
|
||||
@@ -83,6 +87,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpRepository _jumpRepository;
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
private readonly IStatsService _statsService;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainBusiness.Interfaces;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -9,9 +10,13 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public StatsService(IJumpService jumpService)
|
||||
public StatsService(IJumpService jumpService,
|
||||
IUserStatsRepository userStatsRepository,
|
||||
IIdentityService identityService)
|
||||
{
|
||||
_jumpService = jumpService;
|
||||
_identityService = identityService;
|
||||
_userStatsRepository = userStatsRepository;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
@@ -40,207 +45,296 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByAircraft.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.Aircraft.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
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();
|
||||
}
|
||||
|
||||
allStats.ByAircraft = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return results;
|
||||
return allStats.ByAircraft;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByDz.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.DropZone.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
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();
|
||||
}
|
||||
|
||||
allStats.ByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return results;
|
||||
return allStats.ByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByGear()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByGear.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => $"{j.Gear.Name} / {j.Gear.MainCanopy}",
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
allStats.ByGear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return results;
|
||||
return allStats.ByGear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByJumpType.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.JumpType.Name,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
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();
|
||||
}
|
||||
|
||||
allStats.ByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return results;
|
||||
return allStats.ByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ByYear.Any())
|
||||
{
|
||||
results = allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
(groupby, jumps) => new Statistic
|
||||
{
|
||||
Label = groupby.ToString(),
|
||||
Nb = jumps.Count()
|
||||
})
|
||||
.ToList();
|
||||
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();
|
||||
}
|
||||
|
||||
allStats.ByYear = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return results;
|
||||
return allStats.ByYear;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByDz.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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();
|
||||
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();
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return results;
|
||||
return allStats.ForLastMonthByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastMonthByJumpType.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var monthOfLastJump = lastJump.JumpDate.Month;
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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();
|
||||
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();
|
||||
}
|
||||
|
||||
allStats.ForLastMonthByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return results;
|
||||
return allStats.ForLastMonthByJumpType;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByDz()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByDz.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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();
|
||||
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();
|
||||
}
|
||||
|
||||
allStats.ForLastYearByDz = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return results;
|
||||
return allStats.ForLastYearByDz;
|
||||
}
|
||||
|
||||
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
|
||||
{
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
if (allJumps.Any())
|
||||
var allStats = GetAllStats();
|
||||
if (!allStats.ForLastYearByJumpType.Any())
|
||||
{
|
||||
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First();
|
||||
var yearOfLastJump = lastJump.JumpDate.Year;
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<Statistic>();
|
||||
|
||||
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();
|
||||
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();
|
||||
}
|
||||
|
||||
allStats.ForLastYearByJumpType = results;
|
||||
_userStatsRepository.Update(allStats);
|
||||
}
|
||||
|
||||
return results;
|
||||
return allStats.ForLastYearByJumpType;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
var tmp = new UserStats();
|
||||
tmp.User = _identityService.ConnectedUser;
|
||||
_userStatsRepository.Add(tmp);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private UserStats GetAllStats()
|
||||
{
|
||||
var allStats = _userStatsRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
{
|
||||
allStats = new UserStats();
|
||||
allStats.User = _identityService.ConnectedUser;
|
||||
_userStatsRepository.Add(allStats);
|
||||
}
|
||||
|
||||
return allStats;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IJumpService _jumpService;
|
||||
private readonly IUserStatsRepository _userStatsRepository;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IUserStatsRepository : IRepository<UserStats>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
UserStats GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ namespace skydiveLogs_api.Infrastructure.Interfaces
|
||||
ILiteCollection<UserImage> CollOfImage { get; }
|
||||
ILiteCollection<Jump> CollOfJump { get; }
|
||||
ILiteCollection<JumpType> CollOfJumpType { get; }
|
||||
ILiteCollection<UserStats> CollOfStats { get; }
|
||||
ILiteCollection<User> CollOfUser { get; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
BsonMapper.Global.Entity<UserImage>().DbRef(x => x.User, "User");
|
||||
|
||||
BsonMapper.Global.Entity<UserStats>().DbRef(x => x.User, "User");
|
||||
|
||||
BsonMapper.Global.Entity<Gear>().DbRef(x => x.User, "User");
|
||||
|
||||
BsonMapper.Global.Entity<FavoriteDropZone>().DbRef(x => x.User, "User");
|
||||
@@ -52,6 +54,7 @@ namespace skydiveLogs_api.Infrastructure
|
||||
public ILiteCollection<UserImage> CollOfImage => _db.GetCollection<UserImage>();
|
||||
public ILiteCollection<Jump> CollOfJump => _db.GetCollection<Jump>();
|
||||
public ILiteCollection<JumpType> CollOfJumpType => _db.GetCollection<JumpType>();
|
||||
public ILiteCollection<UserStats> CollOfStats => _db.GetCollection<UserStats>();
|
||||
public ILiteCollection<User> CollOfUser => _db.GetCollection<User>();
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
72
Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs
Normal file
72
Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using LiteDB;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class UserStatsRepository : IUserStatsRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public UserStatsRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.CollOfStats;
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(UserStats newStats)
|
||||
{
|
||||
int result;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<UserStats> GetAll()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public UserStats GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
}
|
||||
|
||||
public UserStats GetById(int id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Update(UserStats stats)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly ILiteCollection<UserStats> _col;
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ namespace skydiveLogs_api.Ioc
|
||||
_services.AddScoped<IUserRepository, UserRepository>();
|
||||
_services.AddScoped<IUserImageRepository, UserImageRepository>();
|
||||
_services.AddScoped<IFavoriteDropZoneRepository, FavoriteDropZoneRepository>();
|
||||
_services.AddScoped<IUserStatsRepository, UserStatsRepository>();
|
||||
|
||||
string connectionString = _configuration.GetConnectionString("DefaultConnection");
|
||||
_services.AddSingleton<IDataProvider>(c => new LiteDbProvider(connectionString));
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class Aircraft
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string ImageData { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class DatabaseOptions
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class DropZone
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Latitude { get; set; }
|
||||
|
||||
public string Longitude { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Address { get; set; }
|
||||
|
||||
public string Website { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public IEnumerable<string> Type { get; set; }
|
||||
|
||||
public bool IsFavorite { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class Gear
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Manufacturer { get; set; }
|
||||
|
||||
public int MinSize { get; set; }
|
||||
|
||||
public int MaxSize { get; set; }
|
||||
|
||||
public string Aad { get; set; }
|
||||
|
||||
public string MainCanopy { get; set; }
|
||||
|
||||
public string ReserveCanopy { get; set; }
|
||||
|
||||
public User User { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class Jump
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public JumpType JumpType { get; set; }
|
||||
|
||||
public Aircraft Aircraft { get; set; }
|
||||
|
||||
public DropZone DropZone { get; set; }
|
||||
|
||||
public Gear Gear { get; set; }
|
||||
|
||||
public User User { get; set; }
|
||||
|
||||
public int ExitAltitude { get; set; }
|
||||
|
||||
public int DeployAltitude { get; set; }
|
||||
|
||||
public bool WithCutaway { get; set; }
|
||||
|
||||
public string Notes { get; set; }
|
||||
|
||||
public DateTime JumpDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class JumpType
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class SimpleSummary
|
||||
{
|
||||
public int TotalJumps { get; set; }
|
||||
|
||||
public int TotalCutaways { get; set; }
|
||||
|
||||
public Jump LastJump { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class Statistic
|
||||
{
|
||||
public string Label { get; set; }
|
||||
|
||||
public int Nb { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string Login { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
namespace skydiveLogs_api.Domain
|
||||
{
|
||||
public class UserImage
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string Data { get; set; }
|
||||
|
||||
public User User { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<RootNamespace>skydiveLogs_api.Domain</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -20,7 +20,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="10.1.1" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.0" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user