2024-05-05 22:02:53 +04:00
|
|
|
|
using CarShowroomDataModels.Views;
|
2024-05-05 19:18:53 +04:00
|
|
|
|
using CarShowroomDataModels.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-05-03 11:28:27 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2024-05-05 19:18:53 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2024-05-03 11:28:27 +04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CarShowroomDatabaseStorage.Entities
|
|
|
|
|
{
|
2024-05-05 19:18:53 +04:00
|
|
|
|
[Table("employee")]
|
|
|
|
|
[Index(nameof(Email), IsUnique = true)]
|
2024-05-03 11:28:27 +04:00
|
|
|
|
public class Employee : IEmployee
|
|
|
|
|
{
|
2024-05-05 19:18:53 +04:00
|
|
|
|
[Column("employee_id")]
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
[Column("employee_name")]
|
|
|
|
|
[MaxLength(50)]
|
|
|
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
[Column("employee_email")]
|
|
|
|
|
[MaxLength(40)]
|
|
|
|
|
public string Email { get; private set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
[Column("employee_password")]
|
|
|
|
|
[MaxLength(32)]
|
|
|
|
|
public string Password { get; private set; } = string.Empty;
|
|
|
|
|
public virtual List<Sale> Sales { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
private Employee() { }
|
|
|
|
|
|
|
|
|
|
private Employee(IEmployee employee)
|
2024-05-03 11:28:27 +04:00
|
|
|
|
{
|
|
|
|
|
Id = employee.Id;
|
|
|
|
|
Name = employee.Name;
|
|
|
|
|
Email = employee.Email;
|
|
|
|
|
Password = employee.Password;
|
|
|
|
|
}
|
2024-05-05 19:18:53 +04:00
|
|
|
|
|
|
|
|
|
public static Employee? Create(IEmployee employee)
|
|
|
|
|
{
|
|
|
|
|
if (employee == null)
|
|
|
|
|
return null;
|
|
|
|
|
return new Employee(employee);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(IEmployee employee)
|
|
|
|
|
{
|
|
|
|
|
if(employee == null)
|
|
|
|
|
return;
|
|
|
|
|
Name = employee.Name;
|
|
|
|
|
Email = employee.Email;
|
|
|
|
|
Password = employee.Password;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 22:58:29 +04:00
|
|
|
|
public EmployeeView GetView()
|
2024-05-05 19:18:53 +04:00
|
|
|
|
{
|
|
|
|
|
return new EmployeeView(this);
|
|
|
|
|
}
|
2024-05-03 11:28:27 +04:00
|
|
|
|
}
|
|
|
|
|
}
|