2023-04-02 16:04:50 +04:00
|
|
|
|
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; }
|
2023-04-05 23:57:45 +04:00
|
|
|
|
[Required, Column(TypeName = "date")]
|
2023-04-02 16:04:50 +04:00
|
|
|
|
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; }
|
2023-04-04 22:42:28 +04:00
|
|
|
|
public virtual WorkInRequest WorkInRequest { get; set; } = new();
|
2023-04-06 22:44:17 +04:00
|
|
|
|
public static WorkPayment? Create(CarServiceDbContext context, WorkPaymentBindingModel? model)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new()
|
|
|
|
|
{
|
|
|
|
|
DatePayment = model.DatePayment,
|
|
|
|
|
Sum = model.Sum,
|
2023-04-06 22:44:17 +04:00
|
|
|
|
WorkInRequest = context.WorksInRequest.First(x => x.Id == model.WorkInRequestId)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2023-04-06 22:44:17 +04:00
|
|
|
|
public void Update(CarServiceDbContext context, WorkPaymentBindingModel? model)
|
2023-04-02 16:04:50 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DatePayment = model.DatePayment;
|
|
|
|
|
Sum = model.Sum;
|
2023-04-06 22:44:17 +04:00
|
|
|
|
WorkInRequest = context.WorksInRequest.First(x => x.Id == model.WorkInRequestId);
|
2023-04-02 16:04:50 +04:00
|
|
|
|
}
|
|
|
|
|
public WorkPaymentViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
DatePayment = DatePayment,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
WorkInRequestId = WorkInRequestId
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|