diff --git a/ComputerStoreContracts/BindingModels/EmployeeBindingModel.cs b/ComputerStoreContracts/BindingModels/EmployeeBindingModel.cs index 4d50ab1..4b0c917 100644 --- a/ComputerStoreContracts/BindingModels/EmployeeBindingModel.cs +++ b/ComputerStoreContracts/BindingModels/EmployeeBindingModel.cs @@ -12,8 +12,8 @@ namespace ComputerStoreContracts.BindingModels public int ID { get; set; } public string Username { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; - public string FirstName { get; set; } = string.Empty; - public string LastName { get; set; } = string.Empty; - public string MiddleName { get; set; } = string.Empty; + public string? FirstName { get; set; } = string.Empty; + public string? LastName { get; set; } = string.Empty; + public string? MiddleName { get; set; } = string.Empty; } } diff --git a/ComputerStoreContracts/ViewModels/EmployeeViewModel.cs b/ComputerStoreContracts/ViewModels/EmployeeViewModel.cs index d36e24b..849b10a 100644 --- a/ComputerStoreContracts/ViewModels/EmployeeViewModel.cs +++ b/ComputerStoreContracts/ViewModels/EmployeeViewModel.cs @@ -18,13 +18,13 @@ namespace ComputerStoreContracts.ViewModels public string Password { get; set; } = string.Empty; [DisplayName("Employee's first name")] - public string FirstName { get; set; } = string.Empty; + public string? FirstName { get; set; } = string.Empty; [DisplayName("Employee's last name")] - public string LastName { get; set; } = string.Empty; + public string? LastName { get; set; } = string.Empty; [DisplayName("Employee's middle name")] - public string MiddleName { get; set; } = string.Empty; + public string? MiddleName { get; set; } = string.Empty; } diff --git a/ComputerStoreDataModels/Models/IEmployeeModel.cs b/ComputerStoreDataModels/Models/IEmployeeModel.cs index 7c191ed..834a9af 100644 --- a/ComputerStoreDataModels/Models/IEmployeeModel.cs +++ b/ComputerStoreDataModels/Models/IEmployeeModel.cs @@ -10,8 +10,8 @@ namespace ComputerStoreDataModels.Models { string Username { get; } string Password { get; } - string FirstName { get; } - string LastName { get; } - string MiddleName { get; } + string? FirstName { get; } + string? LastName { get; } + string? MiddleName { get; } } } diff --git a/ComputerStoreDatabaseImplement/ComputerStoreDatabaseImplement.csproj b/ComputerStoreDatabaseImplement/ComputerStoreDatabaseImplement.csproj index 132c02c..288a160 100644 --- a/ComputerStoreDatabaseImplement/ComputerStoreDatabaseImplement.csproj +++ b/ComputerStoreDatabaseImplement/ComputerStoreDatabaseImplement.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/ComputerStoreDatabaseImplement/Models/Employee.cs b/ComputerStoreDatabaseImplement/Models/Employee.cs new file mode 100644 index 0000000..8e216dd --- /dev/null +++ b/ComputerStoreDatabaseImplement/Models/Employee.cs @@ -0,0 +1,66 @@ +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 PCs { 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 + }; + } +}