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

72 lines
1.6 KiB
C#

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;
/// <summary>
/// Таблица машин
/// </summary>
public partial class Car : ICar
{
/// <summary>
/// Айди машины
/// </summary>
public int Id { get; set; }
/// <summary>
/// Модель машины
/// </summary>
public string Model { get; set; } = null!;
/// <summary>
/// Грузоподъемность
/// </summary>
public int Tonnage { get; set; }
/// <summary>
/// Статус машины
/// </summary>
public int? StatusId { get; set; }
public virtual Status? Status { get; set; }
public virtual ICollection<Voyage> Voyages { get; set; } = new List<Voyage>();
[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
};
}