Add methods used for the graph of the tunnel flights

This commit is contained in:
Sébastien ANDRE
2023-08-16 17:38:50 +02:00
parent 25e403c21f
commit dc06f256b4
5 changed files with 83 additions and 29 deletions

View File

@@ -3,6 +3,7 @@ using skydiveLogs_api.DomainBusiness.Interfaces;
using skydiveLogs_api.DomainService.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
namespace skydiveLogs_api.DomainBusiness
{
@@ -33,6 +34,46 @@ namespace skydiveLogs_api.DomainBusiness
return _tunnelFlightRepository.GetById(id);
}
public int GetTunnelFlightCount()
{
return _tunnelFlightRepository.GetCount(_identityService.ConnectedUser);
}
public IEnumerable<TunnelFlight> GetTunnelFlightsByIndexes(int beginIndex, int endIndex)
{
return _tunnelFlightRepository.GetBetweenIndex(_identityService.ConnectedUser, beginIndex, endIndex);
}
public IEnumerable<Statistic> GetTunnelFlightGroupByMonth(string beginDate, string endDate)
{
var convertedBeginDate = Convert.ToDateTime(beginDate);
var convertedEndDate = Convert.ToDateTime(endDate);
var allTunnelFlights = _tunnelFlightRepository.GetBetweenDate(_identityService.ConnectedUser, convertedBeginDate, convertedEndDate);
var results = Enumerable.Empty<Statistic>();
if (allTunnelFlights.Any())
{
results = allTunnelFlights.GroupBy(j => j.FlightDate.ToString("yy-MM"),
j => j,
(groupby, tunnelFlights) => new Statistic
{
Label = groupby.ToString(),
Nb = tunnelFlights.Sum(t => t.NbMinutes)
})
.ToList();
}
return results;
}
public IEnumerable<TunnelFlight> GetTunnelFlightByDates(string beginDate, string endDate)
{
var convertedBeginDate = Convert.ToDateTime(beginDate);
var convertedEndDate = Convert.ToDateTime(endDate);
return _tunnelFlightRepository.GetBetweenDate(_identityService.ConnectedUser, convertedBeginDate, convertedEndDate);
}
public void AddNewFlight(int tunnelId, TunnelFlight newFlight)
{
var tmp = _dropZoneService.GetDzById(tunnelId);
@@ -51,23 +92,19 @@ namespace skydiveLogs_api.DomainBusiness
_tunnelFlightRepository.Add(newFlight);
}
public int GetTunnelFlightCount()
public void DeleteTunnelFlightById(int id)
{
return _tunnelFlightRepository.GetCount(_identityService.ConnectedUser);
_tunnelFlightRepository.DeleteById(id);
}
public IEnumerable<TunnelFlight> GetTunnelFlightsByIndexes(int beginIndex, int endIndex)
public void UpdateTunnelFlight(int id, TunnelFlight updatedTunnelFlight)
{
return _tunnelFlightRepository.GetBetweenIndex(_identityService.ConnectedUser, beginIndex, endIndex);
}
public IEnumerable<TunnelFlight> GetTunnelFlightByDates(string beginDate, string endDate)
{
var convertedBeginDate = Convert.ToDateTime(beginDate);
var convertedEndDate = Convert.ToDateTime(endDate);
return _tunnelFlightRepository.GetBetweenDate(_identityService.ConnectedUser, convertedBeginDate, convertedEndDate);
var myTunnelFlight = GetTunnelFlightById(id);
myTunnelFlight.FlightDate = updatedTunnelFlight.FlightDate;
myTunnelFlight.NbMinutes = updatedTunnelFlight.NbMinutes;
myTunnelFlight.Notes = updatedTunnelFlight.Notes;
_tunnelFlightRepository.Update(myTunnelFlight);
}
#endregion Public Methods