2024-04-30 15:57:30 +04:00
|
|
|
|
using ComputerHardwareStoreContracts.BindingModels;
|
|
|
|
|
using ComputerHardwareStoreContracts.ViewModels;
|
|
|
|
|
using ComputerHardwareStoreDataModels.Models;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-04-30 18:16:30 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2024-04-30 15:57:30 +04:00
|
|
|
|
|
|
|
|
|
namespace ComputerHardwareStoreDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class StoreKeeper : IStoreKeeperModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
|
|
|
|
|
public string Login { get; private set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
|
|
|
|
|
public string Password { get; private set; } = string.Empty;
|
2024-04-30 18:16:30 +04:00
|
|
|
|
[ForeignKey("StoreKeeperId")]
|
|
|
|
|
public virtual List<Product> Products { get; set; } = new();
|
|
|
|
|
[ForeignKey("StoreKeeperId")]
|
|
|
|
|
public virtual List<Component> Components { get; set; } = new();
|
|
|
|
|
|
2024-04-30 15:57:30 +04:00
|
|
|
|
|
|
|
|
|
public static StoreKeeper? Create(ComputerHardwareStoreDBContext context, StoreKeeperBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new StoreKeeper()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
Login = model.Login,
|
|
|
|
|
Password = model.Password,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(StoreKeeperBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name;
|
|
|
|
|
Password = string.IsNullOrEmpty(model.Password) ? Password : model.Password;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public StoreKeeperViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
Name = Name,
|
|
|
|
|
Login = Login,
|
|
|
|
|
Password = Password
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|