2024-04-07 18:18:58 +04:00
|
|
|
|
using IceCreamShopContracts.BindingModels;
|
|
|
|
|
using IceCreamShopContracts.ViewModels;
|
|
|
|
|
using IceCreamShopDataModels.Models;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2024-05-16 22:59:22 +04:00
|
|
|
|
using System.Runtime.Serialization;
|
2024-04-07 18:18:58 +04:00
|
|
|
|
|
|
|
|
|
namespace IceCreamShopDatabaseImplement.Models
|
|
|
|
|
{
|
2024-05-16 22:59:22 +04:00
|
|
|
|
[DataContract]
|
2024-04-07 18:18:58 +04:00
|
|
|
|
public class Client : IClientModel
|
|
|
|
|
{
|
2024-05-16 22:59:22 +04:00
|
|
|
|
[DataMember]
|
2024-04-07 18:18:58 +04:00
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
|
2024-05-16 22:59:22 +04:00
|
|
|
|
[DataMember]
|
2024-04-07 18:18:58 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public string ClientFIO { get; private set; } = string.Empty;
|
|
|
|
|
|
2024-05-16 22:59:22 +04:00
|
|
|
|
[DataMember]
|
2024-04-07 18:18:58 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public string Email { get; private set; } = string.Empty;
|
|
|
|
|
|
2024-05-16 22:59:22 +04:00
|
|
|
|
[DataMember]
|
2024-04-07 18:18:58 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public string Password { get; private set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
[ForeignKey("ClientId")]
|
|
|
|
|
public virtual List<Order> Orders { get; set; } = new();
|
|
|
|
|
|
2024-05-06 02:20:47 +04:00
|
|
|
|
[ForeignKey("ClientId")]
|
|
|
|
|
public virtual List<MessageInfo> ClientMessages { get; set; } = new();
|
|
|
|
|
|
2024-04-07 18:18:58 +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
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|