CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Client.cs
Илья Федотов 7f9720200f fix Db models
2024-05-25 22:32:22 +04:00

64 lines
1.7 KiB
C#

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
{
public class Client : IClientModel {
public int ID { get; set; }
[Required]
public string ClientFIO { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
//незаконная магия ленивой загрузки
[ForeignKey("ClientID")]
public virtual List<Order> Orders { get; set; } = new();
public static Client? Create(ClientBindingModel? model)
{
if(model == null)
{
return null;
}
return new Client()
{
ID = model.ID,
ClientFIO = model.ClientFIO,
Password = model.Password,
Email = model.Email
};
}
public void Update(ClientBindingModel? model)
{
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
};
}
}