LabSubd/Subd/DataBase/Car.cs

72 lines
1.6 KiB
C#
Raw Normal View History

using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
2023-05-05 21:47:09 +04:00
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>();
2023-05-05 21:47:09 +04:00
[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,
2023-05-05 21:47:09 +04:00
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 ,
2023-05-05 21:47:09 +04:00
StatusTitle = Status?.Title
};
}