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

64 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 WorkInRequest : IWorkInRequestModel
{
public int Id { get; private set; }
[Required]
public int Count { get; private set; }
[Required, Column(TypeName = "decimal (10,2)")]
public decimal Cost { get; private set; }
[Required]
public int RepairRequestId { get; private set; }
[Required]
public int WorkId { get; private set; }
/// <summary>
/// Оплаты за ремонт
/// </summary>
[ForeignKey("WorkInRequestId")]
public virtual List<WorkPayment> WorkPayments { get; set; } = new();
public virtual RepairRequest RepairRequest { get; set; } = new();
public virtual Work Work { get; set; } = new();
public static WorkInRequest? Create(WorkInRequestBindingModel? model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Count = model.Count,
Cost = model.Cost,
RepairRequestId = model.RepairRequestId,
WorkId = model.WorkId
};
}
public void Update(WorkInRequestBindingModel? model)
{
if (model == null)
{
return;
}
Id = model.Id;
Count = model.Count;
Cost = model.Cost;
RepairRequestId = model.RepairRequestId;
WorkId = model.WorkId;
}
public WorkInRequestViewModel GetViewModel => new()
{
Id = Id,
Count = Count,
Cost = Cost,
RepairRequestId = RepairRequestId,
WorkId = WorkId
};
}
}