autobus-api_old/AutobusApi.Application/RouteSearch/EnrollmentAddressVertex.cs

76 lines
2.0 KiB
C#

using AutobusApi.Domain.Entities;
namespace AutobusApi.Application.RouteSearch;
public class EnrollmentAddressVertex
{
public EnrollmentAddressVertex(VehicleEnrollment vehicleEnrollment, Address address)
{
VehicleEnrollment = vehicleEnrollment;
Address = address;
}
public VehicleEnrollment VehicleEnrollment { get; set; }
public Address Address { get; set; }
public DateTime GetDepartureDateTimeUtc()
{
DateTime result = VehicleEnrollment.DepartureDateTimeUtc;
var rouetAddressDetails = VehicleEnrollment.RouteAddressDetails.OrderBy(rad => rad.RouteAddress.Order);
rouetAddressDetails.First().CurrentAddressStopTime = TimeSpan.Zero;
foreach (var rad in rouetAddressDetails)
{
result += rad.CurrentAddressStopTime;
if (rad.RouteAddress.Address.Id == Address.Id)
{
break;
}
result += rad.TimeToNextAddress;
}
return result;
}
public DateTime GetArrivalDateTimeUtc()
{
DateTime result = VehicleEnrollment.DepartureDateTimeUtc;
var rouetAddressDetails = VehicleEnrollment.RouteAddressDetails.OrderBy(rad => rad.RouteAddress.Order);
rouetAddressDetails.First().CurrentAddressStopTime = TimeSpan.Zero;
foreach (var rad in rouetAddressDetails)
{
if (rad.RouteAddress.Address.Id == Address.Id)
{
break;
}
result += rad.CurrentAddressStopTime;
result += rad.TimeToNextAddress;
}
return result;
}
public override bool Equals(object? obj)
{
if (obj == null || !(obj is EnrollmentAddressVertex))
{
return false;
}
EnrollmentAddressVertex other = (EnrollmentAddressVertex)obj;
return this.Address.Id == other.Address.Id;
}
public override int GetHashCode()
{
return Address.Id.GetHashCode();
}
}