ISEbd-21_Melnikov_I.O._CarS.../CarService/CarServiceDatabase/Models/RepairRequest.cs

67 lines
1.6 KiB
C#

using CarServiceContracts.BindingModels;
using CarServiceContracts.Models;
using CarServiceContracts.ViewModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace CarServiceDatabase.Models
{
public class RepairRequest : IRepairRequestModel
{
public int Id { get; private set; }
[Required]
public DateTime DateCreated { get; private set; } = DateTime.Now;
[Required]
public int VehicleId { get; private set; }
/// <summary>
/// Работы в заявке
/// </summary>
[ForeignKey("RepairRequestId")]
public virtual List<WorkInRequest> WorksInRequest { get; set; } = new();
/// <summary>
/// Затраты на ремонт
/// </summary>
[ForeignKey("RepairRequestId")]
public virtual List<ItemForRepair> ItemsForRepair { get; set; } = new();
public virtual Vehicle Vehicle { get; set; } = new();
public static RepairRequest? Create(RepairRequestBindingModel? model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
DateCreated = model.DateCreated,
VehicleId = model.VehicleId
};
}
public static RepairRequest Create(RepairRequestViewModel model)
{
return new()
{
Id = model.Id,
DateCreated = model.DateCreated,
VehicleId = model.VehicleId
};
}
public void Update(RepairRequestBindingModel? model)
{
if (model == null)
{
return;
}
Id = model.Id;
DateCreated = model.DateCreated;
VehicleId = model.VehicleId;
}
public RepairRequestViewModel GetViewModel => new()
{
Id = Id,
DateCreated = DateCreated,
VehicleId = VehicleId
};
}
}