Guarantor: Contracts + DatabaseImplementation partly.

This commit is contained in:
Yuee Shiness 2023-04-05 22:13:48 +04:00
parent ef018c1331
commit 377a803ac1
5 changed files with 80 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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; }
}
}

View File

@ -6,4 +6,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ComputerStoreContracts\ComputerStoreContracts.csproj" />
<ProjectReference Include="..\ComputerStoreDataModels\ComputerStoreDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -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<PC> 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
};
}
}