68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using CarCenterContracts.BindingModels;
|
|
using CarCenterContracts.ViewModels;
|
|
using CarCenterDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CarCenterDatabaseImplement.Models
|
|
{
|
|
public class Presale : IPresaleModel
|
|
{
|
|
public int Id { get; set; }
|
|
[Required]
|
|
public DateTime PresaleDate { get; set; } = DateTime.Now;
|
|
[Required]
|
|
public int EmployeeId { get; set; }
|
|
public virtual Employee Employee { get; set; } = new();
|
|
public int? TypeOfJobId {get; set; }
|
|
public virtual TypeOfJob? TypeOfJob { get; set; }
|
|
[ForeignKey("PresaleId")]
|
|
public virtual List<PresaleCar> PresaleCars { get; set; } = new();
|
|
public static Presale? Create(CarCenterDatabase context, PresaleBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Presale()
|
|
{
|
|
Id = model.Id,
|
|
PresaleDate = model.PresaleDate,
|
|
EmployeeId = model.EmployeeId,
|
|
Employee = context.Employees.First(x => x.Id == model.EmployeeId)
|
|
};
|
|
}
|
|
public static Presale? Create(CarCenterDatabase context, PresaleViewModel model)
|
|
{
|
|
return new Presale()
|
|
{
|
|
Id = model.Id,
|
|
PresaleDate = model.PresaleDate,
|
|
EmployeeId = model.EmployeeId,
|
|
Employee = context.Employees.First(x => x.Id == model.EmployeeId)
|
|
};
|
|
}
|
|
public void Update(PresaleBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
if (model.TypeOfJobId.HasValue) TypeOfJobId = TypeOfJobId;
|
|
}
|
|
public PresaleViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
TypeOfJobId = TypeOfJobId,
|
|
PresaleDate = PresaleDate,
|
|
EmployeeId = EmployeeId,
|
|
EmployeeName = Employee.Surname + " " + Employee.Name + " " + Employee.Patronymic,
|
|
};
|
|
}
|
|
}
|