Update StatsByByAircraft
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
IEnumerable<Statistic> GetStats();
|
||||
IEnumerable<StatsByAircraft> GetStats();
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
|
||||
@@ -23,71 +23,39 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
#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()
|
||||
public IEnumerable<StatsByAircraft> GetStats()
|
||||
{
|
||||
var allStats = _statsByAircraftRepository.GetAll(_identityService.ConnectedUser);
|
||||
if (allStats == null)
|
||||
if (!allStats.Any())
|
||||
{
|
||||
allStats = new UserStats
|
||||
var allJumps = _jumpService.GetAllJumps();
|
||||
var results = new List<StatsByAircraft>();
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -2,12 +2,7 @@ using skydiveLogs_api.Domain;
|
||||
|
||||
namespace skydiveLogs_api.DomainService.Repositories
|
||||
{
|
||||
public interface IStatsByAircraftRepository : IRepository<StatsByAircraft>
|
||||
public interface IStatsByAircraftRepository : IStatsRepository<StatsByAircraft>
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
StatsByAircraft GetAll(User user);
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsByAircraft newStats)
|
||||
public int Add(IEnumerable<StatsByAircraft> 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<StatsByAircraft> 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<StatsByAircraft> 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
|
||||
|
||||
Reference in New Issue
Block a user