Split tables for the stats #6
@@ -0,0 +1,14 @@
|
|||||||
|
using skydiveLogs_api.Domain;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||||
|
{
|
||||||
|
public interface IStatsByAircraftService
|
||||||
|
{
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
IEnumerable<Statistic> GetStats();
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
100
Back/skydiveLogs-api.DomainBusiness/StatsByAircraftService.cs
Normal file
100
Back/skydiveLogs-api.DomainBusiness/StatsByAircraftService.cs
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
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<Statistic> GetStats()
|
||||||
|
{
|
||||||
|
// var allStats = GetAllStats();
|
||||||
|
// if (!allStats.ByDz.Any())
|
||||||
|
// {
|
||||||
|
// 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()
|
||||||
|
// })];
|
||||||
|
// }
|
||||||
|
|
||||||
|
// allStats.ByDz = results;
|
||||||
|
// _userStatsRepository.Update(allStats);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return allStats.ByDz;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void Reset()
|
||||||
|
// {
|
||||||
|
// var resetStats = new UserStats();
|
||||||
|
// var myStats = GetAllStats();
|
||||||
|
// myStats.ByAircraft = resetStats.ByAircraft;
|
||||||
|
// myStats.ByDz = resetStats.ByDz;
|
||||||
|
// myStats.ByGear = resetStats.ByGear;
|
||||||
|
// myStats.ByJumpType = resetStats.ByJumpType;
|
||||||
|
// myStats.ByYear = resetStats.ByYear;
|
||||||
|
// myStats.ForLastMonthByDz = resetStats.ForLastMonthByDz;
|
||||||
|
// myStats.ForLastMonthByJumpType = resetStats.ForLastMonthByJumpType;
|
||||||
|
// myStats.ForLastYearByDz = resetStats.ForLastYearByDz;
|
||||||
|
// myStats.ForLastYearByJumpType = resetStats.ForLastYearByJumpType;
|
||||||
|
// myStats.ByYearByJumpType = resetStats.ByYearByJumpType;
|
||||||
|
|
||||||
|
// _userStatsRepository.Update(myStats);
|
||||||
|
// }
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
|
|
||||||
|
private UserStats GetAllStats()
|
||||||
|
{
|
||||||
|
var allStats = _statsByAircraftRepository.GetAll(_identityService.ConnectedUser);
|
||||||
|
if (allStats == null)
|
||||||
|
{
|
||||||
|
allStats = new UserStats
|
||||||
|
{
|
||||||
|
User = _identityService.ConnectedUser
|
||||||
|
};
|
||||||
|
_statsByAircraftRepository.Add(allStats);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Private Methods
|
||||||
|
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly IIdentityService _identityService;
|
||||||
|
private readonly IJumpService _jumpService;
|
||||||
|
private readonly IStatsByAircraftRepository _statsByAircraftRepository;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using skydiveLogs_api.Domain;
|
||||||
|
|
||||||
|
namespace skydiveLogs_api.DomainService.Repositories
|
||||||
|
{
|
||||||
|
public interface IStatsByAircraftRepository : IRepository<StatsByAircraft>
|
||||||
|
{
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
StatsByAircraft GetAll(User user);
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
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 StatsByAircraftRepository : IStatsByAircraftRepository
|
||||||
|
{
|
||||||
|
#region Public Constructors
|
||||||
|
|
||||||
|
public StatsByAircraftRepository(IDataProvider dataProvider)
|
||||||
|
{
|
||||||
|
_dataProvider = dataProvider;
|
||||||
|
_col = _dataProvider.CollOfStatsByAircraft;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Constructors
|
||||||
|
|
||||||
|
#region Public Methods
|
||||||
|
|
||||||
|
public int Add(StatsByAircraft newStats)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tmp = _col.Insert(newStats);
|
||||||
|
result = tmp.AsInt32;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<StatsByAircraft> GetAll()
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StatsByAircraft GetAll(User user)
|
||||||
|
{
|
||||||
|
return _col.Include(x => x.User)
|
||||||
|
.Query()
|
||||||
|
.Where(j => j.User.Id == user.Id)
|
||||||
|
.SingleOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StatsByAircraft GetById(int id)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetCount()
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(StatsByAircraft stats)
|
||||||
|
{
|
||||||
|
return _col.Update(stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Public Methods
|
||||||
|
|
||||||
|
#region Private Fields
|
||||||
|
|
||||||
|
private readonly ILiteCollection<StatsByAircraft> _col;
|
||||||
|
private readonly IDataProvider _dataProvider;
|
||||||
|
|
||||||
|
#endregion Private Fields
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user