PIbd-21_Anisin_R.S._CarRepa.../CarRepairShop/CarRepairShopDatabaseImplement/Models/Client.cs

69 lines
1.8 KiB
C#
Raw Normal View History

2024-04-27 21:36:54 +04:00
using CarRepairShopContracts.BindingModels;
using CarRepairShopContracts.ViewModels;
using CarRepairShopDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2024-05-17 00:53:12 +04:00
using System.Runtime.Serialization;
2024-04-27 21:36:54 +04:00
namespace CarRepairShopDatabaseImplement.Models
{
2024-05-17 00:53:12 +04:00
[DataContract]
2024-04-27 21:36:54 +04:00
public class Client : IClientModel
{
2024-05-17 00:53:12 +04:00
[DataMember]
2024-04-27 21:36:54 +04:00
public int Id { get; private set; }
2024-05-17 00:53:12 +04:00
[DataMember]
2024-04-27 21:36:54 +04:00
[Required]
public string ClientFIO { get; private set; } = string.Empty;
2024-05-17 00:53:12 +04:00
[DataMember]
2024-04-27 21:36:54 +04:00
[Required]
public string Email { get; private set; } = string.Empty;
2024-05-17 00:53:12 +04:00
[DataMember]
2024-04-27 21:36:54 +04:00
[Required]
public string Password { get; private set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
2024-05-16 21:31:36 +04:00
[ForeignKey("ClientId")]
public virtual List<MessageInfo> ClientMessages { get; set; } = new();
2024-04-27 21:36:54 +04:00
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
}
}