63 lines
1.5 KiB
C#
63 lines
1.5 KiB
C#
|
using CarServiceContracts.BindingModels;
|
|||
|
using CarServiceContracts.Models;
|
|||
|
using CarServiceContracts.ViewModels;
|
|||
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
|
|||
|
namespace CarServiceDatabase.Models
|
|||
|
{
|
|||
|
public class WorkPayment : IWorkPaymentModel
|
|||
|
{
|
|||
|
public int Id { get; private set; }
|
|||
|
[Required]
|
|||
|
public DateTime DatePayment { get; private set; } = DateTime.Now;
|
|||
|
[Required, Column(TypeName = "decimal (10,2)")]
|
|||
|
public decimal Sum { get; private set; }
|
|||
|
[Required]
|
|||
|
public int WorkInRequestId { get; private set; }
|
|||
|
public static WorkPayment? Create(WorkPaymentBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
DatePayment = model.DatePayment,
|
|||
|
Sum = model.Sum,
|
|||
|
WorkInRequestId = model.WorkInRequestId
|
|||
|
};
|
|||
|
}
|
|||
|
public static WorkPayment Create(WorkPaymentViewModel model)
|
|||
|
{
|
|||
|
return new()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
DatePayment = model.DatePayment,
|
|||
|
Sum = model.Sum,
|
|||
|
WorkInRequestId = model.WorkInRequestId
|
|||
|
};
|
|||
|
}
|
|||
|
public void Update(WorkPaymentBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Id = model.Id;
|
|||
|
DatePayment = model.DatePayment;
|
|||
|
Sum = model.Sum;
|
|||
|
WorkInRequestId = model.WorkInRequestId;
|
|||
|
}
|
|||
|
public WorkPaymentViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
DatePayment = DatePayment,
|
|||
|
Sum = Sum,
|
|||
|
WorkInRequestId = WorkInRequestId
|
|||
|
};
|
|||
|
}
|
|||
|
}
|