using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
namespace DataBase;
///
/// Таблица машин
///
public partial class Car : ICar
{
///
/// Айди машины
///
public int Id { get; set; }
///
/// Модель машины
///
public string Model { get; set; } = null!;
///
/// Грузоподъемность
///
public int Tonnage { get; set; }
///
/// Статус машины
///
public int? StatusId { get; set; }
public virtual Status? Status { get; set; }
public virtual ICollection Voyages { get; set; } = new List();
[NotMapped]
public string? StatusTitle { get; set; } = string.Empty;
public static Car Create(LogisticContext context, CarBM model)
{
return new Car()
{
Id = model.Id,
Model = model.Model,
Tonnage = model.Tonnage,
StatusId= model.StatusId,
StatusTitle = model.StatusTitle,
};
}
public void Update(CarBM model)
{
Model = model.Model;
Tonnage = model.Tonnage;
StatusTitle = model.StatusTitle;
StatusId = model.StatusId;
}
public CarVM GetViewModel => new()
{
Id = Id,
Model = Model,
Tonnage = Tonnage,
StatusId = StatusId ,
StatusTitle = Status?.Title
};
}