SUBD_PIbd-23_ZakharovRA/CarShowroom/CarShowroomDatabaseStorage/Entities/Client.cs
2024-05-05 21:21:25 +04:00

61 lines
1.6 KiB
C#

using CarShowroomContracts.AbstractModels;
using CarShowroomContracts.Views;
using CarShowroomDataModels.Models;
using Microsoft.EntityFrameworkCore;
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 CarShowroomDatabaseStorage.Entities
{
[Table("client")]
[Index(nameof(PhoneNumber), IsUnique = true)]
public class Client : IClient
{
[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_phonenumber")]
[MaxLength(25)]
public string PhoneNumber { get; private set; } = string.Empty;
public virtual List<Sale> Sales { get; set; } = new();
private Client() { }
private Client(IClient client)
{
Id = client.Id;
Name = client.Name;
PhoneNumber = client.PhoneNumber;
}
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;
PhoneNumber = client.PhoneNumber;
}
public ClientView GetClientView()
{
return new ClientView(this);
}
}
}