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 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();
|
2023-04-04 22:42:28 +04:00
|
|
|
|
public virtual RepairRequest RepairRequest { get; set; } = new();
|
|
|
|
|
public virtual Work Work { get; set; } = new();
|
2023-04-02 16:04:50 +04:00
|
|
|
|
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 static WorkInRequest Create(WorkInRequestViewModel model)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|