LabSubd/Subd/DataBase/Voyage.cs
2023-05-05 20:47:09 +03:00

110 lines
2.7 KiB
C#

using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace DataBase;
/// <summary>
/// Таблица рейсов
/// </summary>
public partial class Voyage : IVoyage
{
/// <summary>
/// Айди рейса
/// </summary>
public int Id { get; set; }
/// <summary>
/// Машина для рейса
/// </summary>
public int? CarId { get; set; }
/// <summary>
/// Водитель для рейса
/// </summary>
public int? HumanId { get; set; }
/// <summary>
/// Компания, заказавшая рейс
/// </summary>
public int? CompanyId { get; set; }
/// <summary>
/// Маршрут рейса
/// </summary>
public int? RouteId { get; set; }
/// <summary>
/// Дата отправки
/// </summary>
public DateOnly? DateStart { get; set; }
/// <summary>
/// Дедлайн
/// </summary>
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
};
}