2023-04-05 22:13:48 +04:00
|
|
|
|
using ComputerStoreDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ComputerStoreContracts.BindingModels;
|
|
|
|
|
using ComputerStoreContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace ComputerStoreDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Employee : IEmployeeModel
|
|
|
|
|
{
|
|
|
|
|
public int ID { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public string Username { get; private set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public string Password { get; private set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public string? FirstName { get; private set; } = string.Empty;
|
|
|
|
|
public string? LastName { get; private set; } = string.Empty;
|
|
|
|
|
public string? MiddleName { get; private set; } = string.Empty;
|
|
|
|
|
|
2023-04-06 17:00:40 +04:00
|
|
|
|
[ForeignKey("EmployeeID")]
|
|
|
|
|
public virtual List<PC> PCs { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
[ForeignKey("EmployeeID")]
|
|
|
|
|
public virtual List<Product> Products { get; set; } = new();
|
2023-04-05 22:13:48 +04:00
|
|
|
|
|
|
|
|
|
public static Employee? Create(EmployeeBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Employee()
|
|
|
|
|
{
|
|
|
|
|
ID = model.ID,
|
|
|
|
|
Username = model.Username,
|
|
|
|
|
Password = model.Password,
|
|
|
|
|
FirstName = model.FirstName,
|
|
|
|
|
LastName = model.LastName,
|
|
|
|
|
MiddleName = model.MiddleName
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(EmployeeBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null) { return; }
|
|
|
|
|
Username = model.Username;
|
|
|
|
|
Password = model.Password;
|
|
|
|
|
FirstName = model.FirstName;
|
|
|
|
|
LastName = model.LastName;
|
|
|
|
|
MiddleName = model.MiddleName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EmployeeViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
ID = ID,
|
|
|
|
|
Username = Username,
|
|
|
|
|
Password = Password,
|
|
|
|
|
FirstName = FirstName,
|
|
|
|
|
LastName = LastName,
|
|
|
|
|
MiddleName = MiddleName
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|