2024-05-25 13:06:38 +04:00
|
|
|
|
using ElectronicsShopContracts.BindingModels;
|
|
|
|
|
using ElectronicsShopContracts.ViewModels;
|
|
|
|
|
using ElectronicsShopDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ElectronicsShopDataBaseImplement.Models
|
|
|
|
|
{
|
2024-05-25 22:32:22 +04:00
|
|
|
|
public class Client : IClientModel {
|
2024-05-25 13:06:38 +04:00
|
|
|
|
public int ID { get; set; }
|
2024-05-25 22:32:22 +04:00
|
|
|
|
|
2024-05-25 13:06:38 +04:00
|
|
|
|
[Required]
|
2024-05-25 22:32:22 +04:00
|
|
|
|
public string ClientFIO { get; set; } = string.Empty;
|
|
|
|
|
|
2024-05-25 13:06:38 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public string Password { get; set; } = string.Empty;
|
2024-05-25 22:32:22 +04:00
|
|
|
|
|
|
|
|
|
[Required]
|
2024-05-25 13:06:38 +04:00
|
|
|
|
public string Email { get; set; } = string.Empty;
|
|
|
|
|
|
2024-05-25 22:32:22 +04:00
|
|
|
|
//незаконная магия ленивой загрузки
|
|
|
|
|
[ForeignKey("ClientID")]
|
|
|
|
|
public virtual List<Order> Orders { get; set; } = new();
|
2024-05-25 13:06:38 +04:00
|
|
|
|
|
2024-05-25 22:32:22 +04:00
|
|
|
|
public static Client? Create(ClientBindingModel? model)
|
2024-05-25 13:06:38 +04:00
|
|
|
|
{
|
|
|
|
|
if(model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Client()
|
|
|
|
|
{
|
|
|
|
|
ID = model.ID,
|
|
|
|
|
ClientFIO = model.ClientFIO,
|
|
|
|
|
Password = model.Password,
|
|
|
|
|
Email = model.Email
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 22:32:22 +04:00
|
|
|
|
public void Update(ClientBindingModel? model)
|
2024-05-25 13:06:38 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ClientFIO = model.ClientFIO;
|
|
|
|
|
Password = model.Password;
|
|
|
|
|
Email = model.Email;
|
|
|
|
|
}
|
|
|
|
|
public ClientViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
ID = ID,
|
|
|
|
|
ClientFIO = ClientFIO,
|
|
|
|
|
Password = Password,
|
|
|
|
|
Email = Email
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|