68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using skydiveLogs_api.Domain;
|
|
using skydiveLogs_api.DomainBusiness.Interfaces;
|
|
using skydiveLogs_api.DomainService.Repositories;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace skydiveLogs_api.DomainBusiness
|
|
{
|
|
public class StatsByByAircraftService : IStatsByAircraftService
|
|
{
|
|
#region Public Constructors
|
|
|
|
public StatsByByAircraftService(IJumpService jumpService,
|
|
IIdentityService identityService,
|
|
IStatsByAircraftRepository statsByAircraftRepository)
|
|
{
|
|
_jumpService = jumpService;
|
|
_identityService = identityService;
|
|
_statsByAircraftRepository = statsByAircraftRepository;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
public IEnumerable<StatsByAircraft> GetStats()
|
|
{
|
|
var allStats = _statsByAircraftRepository.GetAll(_identityService.ConnectedUser);
|
|
if (!allStats.Any())
|
|
{
|
|
var allJumps = _jumpService.GetAllJumps();
|
|
var results = new List<StatsByAircraft>();
|
|
|
|
if (allJumps.Any())
|
|
{
|
|
results = [.. allJumps.GroupBy(j => j.DropZone.Name,
|
|
j => j,
|
|
(groupby, jumps) => new StatsByAircraft
|
|
{
|
|
Label = groupby.ToString(),
|
|
Nb = jumps.Count(),
|
|
User = _identityService.ConnectedUser
|
|
})];
|
|
}
|
|
|
|
_statsByAircraftRepository.Add(results);
|
|
return results;
|
|
}
|
|
|
|
return allStats;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
_statsByAircraftRepository.Delete(_identityService.ConnectedUser);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly IIdentityService _identityService;
|
|
private readonly IJumpService _jumpService;
|
|
private readonly IStatsByAircraftRepository _statsByAircraftRepository;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |