Move ShiftWithTransport class to its own file
Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com>
This commit is contained in:
parent
33c007e66c
commit
abc26066ec
2 changed files with 35 additions and 31 deletions
34
Shared/ShiftWithTransport.cs
Normal file
34
Shared/ShiftWithTransport.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
namespace ShiftScheduler.Shared.Models
|
||||||
|
{
|
||||||
|
// View model that combines shift information with transport data for a specific date
|
||||||
|
public record ShiftWithTransport
|
||||||
|
{
|
||||||
|
public DateTime Date { get; init; }
|
||||||
|
public Shift Shift { get; init; } = new();
|
||||||
|
public TransportConnection? MorningTransport { get; init; }
|
||||||
|
public TransportConnection? AfternoonTransport { get; init; }
|
||||||
|
|
||||||
|
public string GetMorningTransportSummary()
|
||||||
|
{
|
||||||
|
return MorningTransport != null ? FormatTransportSummary(MorningTransport) : string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetAfternoonTransportSummary()
|
||||||
|
{
|
||||||
|
return AfternoonTransport != null ? FormatTransportSummary(AfternoonTransport) : string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string FormatTransportSummary(TransportConnection connection)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(connection.DepartureTime)) return string.Empty;
|
||||||
|
|
||||||
|
var departure = DateTime.TryParse(connection.DepartureTime, out var dep) ? dep.ToString("HH:mm") : connection.DepartureTime;
|
||||||
|
var arrival = DateTime.TryParse(connection.ArrivalTime, out var arr) ? arr.ToString("HH:mm") : connection.ArrivalTime;
|
||||||
|
|
||||||
|
var mainJourney = connection.Sections?.FirstOrDefault()?.Journey;
|
||||||
|
var trainInfo = mainJourney != null ? $"{mainJourney.Category}{mainJourney.Number}" : "Train";
|
||||||
|
|
||||||
|
return $"{trainInfo} {departure}→{arrival}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -94,35 +94,5 @@ namespace ShiftScheduler.Shared.Models
|
||||||
public string Number { get; set; } = string.Empty;
|
public string Number { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
// View model that combines shift information with transport data for a specific date
|
|
||||||
public record ShiftWithTransport
|
|
||||||
{
|
|
||||||
public DateTime Date { get; init; }
|
|
||||||
public Shift Shift { get; init; } = new();
|
|
||||||
public TransportConnection? MorningTransport { get; init; }
|
|
||||||
public TransportConnection? AfternoonTransport { get; init; }
|
|
||||||
|
|
||||||
public string GetMorningTransportSummary()
|
|
||||||
{
|
|
||||||
return MorningTransport != null ? FormatTransportSummary(MorningTransport) : string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetAfternoonTransportSummary()
|
|
||||||
{
|
|
||||||
return AfternoonTransport != null ? FormatTransportSummary(AfternoonTransport) : string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string FormatTransportSummary(TransportConnection connection)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(connection.DepartureTime)) return string.Empty;
|
|
||||||
|
|
||||||
var departure = DateTime.TryParse(connection.DepartureTime, out var dep) ? dep.ToString("HH:mm") : connection.DepartureTime;
|
|
||||||
var arrival = DateTime.TryParse(connection.ArrivalTime, out var arr) ? arr.ToString("HH:mm") : connection.ArrivalTime;
|
|
||||||
|
|
||||||
var mainJourney = connection.Sections?.FirstOrDefault()?.Journey;
|
|
||||||
var trainInfo = mainJourney != null ? $"{mainJourney.Category}{mainJourney.Number}" : "Train";
|
|
||||||
|
|
||||||
return $"{trainInfo} {departure}→{arrival}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue