72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
|
using CarCenterContracts.BindingModels;
|
|||
|
using CarCenterContracts.ViewModels;
|
|||
|
using CarCenterDataModels.Models;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
|
|||
|
namespace CarCenterDataBaseImplement.Models
|
|||
|
{
|
|||
|
public class Sale : ISaleModel
|
|||
|
{
|
|||
|
[Required]
|
|||
|
public DateTime? SaleDate { get; set; } = DateTime.Now;
|
|||
|
[Required]
|
|||
|
public string SalePrice { get; set; } = string.Empty;
|
|||
|
|
|||
|
public int ManagerId { get; private set; }
|
|||
|
|
|||
|
public int Id { get; private set; }
|
|||
|
|
|||
|
public virtual Manager Manager { get; set; }
|
|||
|
|
|||
|
[ForeignKey("SaleId")]
|
|||
|
public virtual List<PreSaleWorkSale> PreSaleWorkSale { get; set; } = new();
|
|||
|
|
|||
|
|
|||
|
[ForeignKey("SaleId")]
|
|||
|
public virtual List<EmployeeSale> EmployeeSale { get; set; } = new();
|
|||
|
|
|||
|
public static Sale? Create(SaleBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new Sale()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
SaleDate = model.SaleDate,
|
|||
|
SalePrice = model.SalePrice,
|
|||
|
ManagerId = model.ManagerId,
|
|||
|
};
|
|||
|
}
|
|||
|
public static Sale Create(SaleViewModel model)
|
|||
|
{
|
|||
|
return new Sale
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
SaleDate = model.SaleDate,
|
|||
|
SalePrice = model.SalePrice,
|
|||
|
ManagerId=model.ManagerId,
|
|||
|
};
|
|||
|
}
|
|||
|
public void Update(SaleBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
SaleDate = model.SaleDate;
|
|||
|
SalePrice = model.SalePrice;
|
|||
|
ManagerId = model.ManagerId;
|
|||
|
}
|
|||
|
public SaleViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
SaleDate = SaleDate,
|
|||
|
SalePrice = SalePrice,
|
|||
|
ManagerId=ManagerId
|
|||
|
};
|
|||
|
}
|
|||
|
}
|