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 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); } } }