using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace DataBase;
///
/// Таблица рейсов
///
public partial class Voyage : IVoyage
{
///
/// Айди рейса
///
public int Id { get; set; }
///
/// Машина для рейса
///
public int? CarId { get; set; }
///
/// Водитель для рейса
///
public int? HumanId { get; set; }
///
/// Компания, заказавшая рейс
///
public int? CompanyId { get; set; }
///
/// Маршрут рейса
///
public int? RouteId { get; set; }
///
/// Дата отправки
///
public DateOnly? DateStart { get; set; }
///
/// Дедлайн
///
public DateOnly? DateEnd { get; set; }
public virtual Car? Car { get; set; }
public virtual Company? Company { get; set; }
public virtual Human? Human { get; set; }
public virtual Route? Route { get; set; }
[NotMapped]
public string? CarName { get; set; } = string.Empty;
[NotMapped]
public string? HumanName { get; set; } = string.Empty;
[NotMapped]
public string? CompanyName { get; set; } = string.Empty;
[NotMapped]
public string? RouteName { get; set; } = string.Empty;
[NotMapped]
public int? Km { get; set; }
public static Voyage Create(LogisticContext context, VoyageBM model)
{
return new Voyage()
{
Id = model.Id,
CarId=model.CarId,
HumanId=model.HumanId,
CompanyId=model.CompanyId,
RouteId=model.RouteId,
DateStart=model.DateStart,
DateEnd=model.DateEnd,
CarName=model.CarName,
HumanName=model.HumanName,
CompanyName=model.CompanyName,
RouteName = model.RouteName
};
}
public VoyageVM GetViewModel => new()
{
Id = Id,
CarId = CarId,
HumanId = HumanId,
CompanyId = CompanyId,
RouteId = RouteId,
DateStart = DateStart,
DateEnd = DateEnd,
CarName = Car?.Model,
HumanName = Human?.Name,
CompanyName = Company?.Title,
RouteName = Route?.PlaceStartNavigation?.Title + " - " + Route?.PlaceStartNavigation?.Title,
Km = Route?.Length
};
public VoyageVM GetReportVM => new()
{
HumanName=Human?.Name,
Km=Km
};
}