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

61 lines
1.6 KiB
C#
Raw Normal View History

2024-05-05 19:18:53 +04:00
using CarShowroomContracts.AbstractModels;
2024-05-05 22:02:53 +04:00
using CarShowroomDataModels.Views;
2024-05-05 19:18:53 +04:00
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")]
2024-05-05 21:21:25 +04:00
[Index(nameof(PhoneNumber), 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]
2024-05-05 21:21:25 +04:00
[Column("client_phonenumber")]
[MaxLength(25)]
public string PhoneNumber { get; private set; } = string.Empty;
2024-05-05 19:18:53 +04:00
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;
2024-05-05 21:21:25 +04:00
PhoneNumber = client.PhoneNumber;
2024-05-03 11:28:27 +04:00
}
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;
2024-05-05 21:21:25 +04:00
PhoneNumber = client.PhoneNumber;
2024-05-05 19:18:53 +04:00
}
public ClientView GetClientView()
{
return new ClientView(this);
}
2024-05-03 11:28:27 +04:00
}
}