diff --git a/Back/skydiveLogs-api.Domain/StatsByAircraft.cs b/Back/skydiveLogs-api.Domain/StatsByAircraft.cs index c957e48..ca46087 100644 --- a/Back/skydiveLogs-api.Domain/StatsByAircraft.cs +++ b/Back/skydiveLogs-api.Domain/StatsByAircraft.cs @@ -6,8 +6,6 @@ namespace skydiveLogs_api.Domain { public string Label { get; set; } - public string Label2 { get; set; } - public int Nb { get; set; } public int Id { get; set; } diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByAircraftService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByAircraftService.cs index 84ad3af..7d9136f 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByAircraftService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsByAircraftService.cs @@ -7,7 +7,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces { #region Public Methods - IEnumerable GetStats(); + IEnumerable GetStats(); #endregion Public Methods } diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsByAircraftService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsByAircraftService.cs index bb74b3d..e95f0cc 100644 --- a/Back/skydiveLogs-api.DomainBusiness/StatsByAircraftService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/StatsByAircraftService.cs @@ -23,71 +23,39 @@ namespace skydiveLogs_api.DomainBusiness #region Public Methods - public IEnumerable GetStats() - { - // var allStats = GetAllStats(); - // if (!allStats.ByDz.Any()) - // { - // var allJumps = _jumpService.GetAllJumps(); - // var results = new List(); - - // 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() + public IEnumerable GetStats() { var allStats = _statsByAircraftRepository.GetAll(_identityService.ConnectedUser); - if (allStats == null) + if (!allStats.Any()) { - allStats = new UserStats + var allJumps = _jumpService.GetAllJumps(); + var results = new List(); + + if (allJumps.Any()) { - User = _identityService.ConnectedUser - }; - _statsByAircraftRepository.Add(allStats); + 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; } - #endregion Private Methods + public void Reset() + { + _statsByAircraftRepository.Delete(_identityService.ConnectedUser); + } + + #endregion Public Methods #region Private Fields diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IStatsByAircraftRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByAircraftRepository.cs index f1e038f..34f29b9 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IStatsByAircraftRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IStatsByAircraftRepository.cs @@ -2,12 +2,7 @@ using skydiveLogs_api.Domain; namespace skydiveLogs_api.DomainService.Repositories { - public interface IStatsByAircraftRepository : IRepository + public interface IStatsByAircraftRepository : IStatsRepository { - #region Public Methods - - StatsByAircraft GetAll(User user); - - #endregion Public Methods } } \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/StatsByAircraftRepository.cs b/Back/skydiveLogs-api.Infrastructure/StatsByAircraftRepository.cs index 63eb76c..e91a992 100644 --- a/Back/skydiveLogs-api.Infrastructure/StatsByAircraftRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/StatsByAircraftRepository.cs @@ -20,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure #region Public Methods - public int Add(StatsByAircraft newStats) + public int Add(IEnumerable newStats) { - int result; + int result = 0; try { - var tmp = _col.Insert(newStats); - result = tmp.AsInt32; + foreach (var newStat in newStats) + { + var tmp = _col.Insert(newStats); + result = tmp; + } } catch { @@ -37,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure return result; } - public StatsByAircraft GetAll(User user) + public IEnumerable GetAll(User user) { return _col.Include(x => x.User) .Query() .Where(j => j.User.Id == user.Id) - .SingleOrDefault(); + .ToList(); } - public bool Update(StatsByAircraft stats) + public bool Update(IEnumerable updatedStats, User user) { - return _col.Update(stats); + Delete(user); + var tmp = Add(updatedStats); + + return tmp != 0; + } + + public bool Delete(User user) + { + var tmp = _col.DeleteMany(s => s.User.Id == user.Id); + return tmp != 0; } #endregion Public Methods