2023-04-02 16:04:50 +04:00
|
|
|
|
using CarServiceContracts.BindingModels;
|
|
|
|
|
using CarServiceContracts.Models;
|
|
|
|
|
using CarServiceContracts.ViewModels;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
|
|
|
|
|
namespace CarServiceDatabase.Models
|
|
|
|
|
{
|
|
|
|
|
public class Vehicle : IVehicleModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
|
public string? Plate { get; private set; }
|
|
|
|
|
public string? VIN { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public int CustomerId { get; private set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Заявки на ремонт
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ForeignKey("VehicleId")]
|
|
|
|
|
public virtual List<RepairRequest> RepairRequests { get; set; } = new();
|
2023-04-04 22:42:28 +04:00
|
|
|
|
public virtual Customer Customer { get; set; } = new();
|
2023-04-02 16:04:50 +04:00
|
|
|
|
public static Vehicle? Create(VehicleBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
Plate = model.Plate,
|
|
|
|
|
VIN = model.VIN,
|
|
|
|
|
CustomerId = model.CustomerId
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(VehicleBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Id = model.Id;
|
|
|
|
|
Name = model.Name;
|
|
|
|
|
Plate = model.Plate;
|
|
|
|
|
VIN = model.VIN;
|
|
|
|
|
CustomerId = model.CustomerId;
|
|
|
|
|
}
|
|
|
|
|
public VehicleViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
Name = Name,
|
|
|
|
|
Plate = Plate,
|
|
|
|
|
VIN = VIN,
|
|
|
|
|
CustomerId = CustomerId
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|