Files
SkydiveLogs/Back/skydiveLogs-api.Business/StatsService.cs
2019-11-10 19:31:55 +01:00

91 lines
3.1 KiB
C#

using System.Collections.Generic;
using System.Linq;
using skydiveLogs_api.Business.Interface;
using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Business
{
public class StatsService : IStatsService
{
public StatsService(IJumpRepository jumpRepository)
{
_jumpRepository = jumpRepository;
}
public IEnumerable<Statistic> GetStatsByAircraft()
{
var allJumps = _jumpRepository.GetAll();
return allJumps.GroupBy(j => j.AircraftId,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsByDz()
{
var allJumps = _jumpRepository.GetAll();
return allJumps.GroupBy(j => j.DropZoneId,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsByJumpType()
{
var allJumps = _jumpRepository.GetAll();
return allJumps.GroupBy(j => j.JumpTypeId,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsByRig()
{
var allJumps = _jumpRepository.GetAll();
return allJumps.GroupBy(j => j.GearId,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsByYear()
{
var allJumps = _jumpRepository.GetAll();
return allJumps.GroupBy(j => j.JumpDate.Year,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
private readonly IJumpRepository _jumpRepository;
}
}