SUBD_PIbd-23_ZakharovRA/CarShowroom/CarShowroomDatabaseStorage/Entities/Client.cs

67 lines
1.8 KiB
C#
Raw Normal View History

2024-05-05 19:18:53 +04:00
using CarShowroomContracts.AbstractModels;
using CarShowroomContracts.Views;
using CarShowroomDataModels.Models;
using Microsoft.EntityFrameworkCore;
2024-05-03 11:28:27 +04:00
using System;
using System.Collections.Generic;
2024-05-05 19:18:53 +04:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2024-05-03 11:28:27 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarShowroomDatabaseStorage.Entities
{
2024-05-05 19:18:53 +04:00
[Table("client")]
[Index(nameof(Email), IsUnique = true)]
2024-05-03 11:28:27 +04:00
public class Client : IClient
{
2024-05-05 19:18:53 +04:00
[Column("client_id")]
public int Id { get; private set; }
[Required]
[Column("client_name")]
[MaxLength(50)]
public string Name { get; private set; } = string.Empty;
[Required]
[Column("client_email")]
[MaxLength(40)]
public string Email { get; private set; } = string.Empty;
[Required]
[Column("client_password")]
[MaxLength(32)]
public string Password { get; private set; } = string.Empty;
public virtual List<Sale> Sales { get; set; } = new();
private Client() { }
private Client(IClient client)
2024-05-03 11:28:27 +04:00
{
Id = client.Id;
Name = client.Name;
Email = client.Email;
Password = client.Password;
}
2024-05-05 19:18:53 +04:00
public static Client? Create(IClient client)
{
if (client == null)
return null;
return new Client(client);
}
public void Update(IClient client)
{
if (client == null)
return;
Name = client.Name;
Email = client.Email;
Password = client.Password;
}
public ClientView GetClientView()
{
return new ClientView(this);
}
2024-05-03 11:28:27 +04:00
}
}