70 lines
2.1 KiB
C#
70 lines
2.1 KiB
C#
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;
|
|
|
|
[ForeignKey("EmployeeID")]
|
|
public virtual List<PC> PCs { get; set; } = new();
|
|
|
|
[ForeignKey("EmployeeID")]
|
|
public virtual List<Product> Products { get; set; } = new();
|
|
|
|
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
|
|
};
|
|
}
|
|
}
|