Case_accounting/CaseAccounting/CaseAccountingDataBaseImplement/Models/Contract.cs
2023-04-07 23:33:56 +04:00

76 lines
1.9 KiB
C#

using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.ViewModels;
using CaseAccountingDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataBaseImplement.Models
{
public class Contract : IContractModel
{
public int Id { get; set; }
[Required]
public string Service { get; set; } = string.Empty;
[Required]
public decimal Coast { get; set; }
[Required]
public DateTime Date { get; set; }
[Required]
public int UserId { get; set; }
public virtual User User { get; set; } = new();
[ForeignKey("ContractId")]
public virtual List<LawyerContracts> LawyerContracts { get; set; } = new();
[ForeignKey("ContractId")]
public virtual List<DealContract> DealContracts { get; set; } = new();
public static Contract? Create(ContractBindingModel? model)
{
if (model == null)
{
return null;
}
return new Contract()
{
Id = model.Id,
Service = model.Service,
Coast = model.Coast,
Date = model.Date,
UserId = model.UserId
};
}
public void Update(ContractBindingModel? model)
{
if (model == null)
{
return;
}
Service = model.Service;
Coast = model.Coast;
Date = model.Date;
}
public ContractViewModel GetViewModel => new()
{
Id = Id,
Service = Service,
Coast = Coast,
Date = Date,
UserId = UserId
};
}
}