PIbd-23_Sergunov_M.A._GiftShop/GiftShop/GiftShopDatabaseImplement/Models/Client.cs

70 lines
1.5 KiB
C#
Raw Normal View History

2023-05-14 11:29:13 +04:00
using GiftShopContracts.BindingModels;
using GiftShopContracts.ViewModels;
using GiftShopDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
2023-06-03 01:27:48 +04:00
using System.Runtime.Serialization;
2023-05-14 11:29:13 +04:00
namespace GiftShopDatabaseImplement.Models
{
2023-06-03 01:27:48 +04:00
[DataContract]
2023-05-14 11:29:13 +04:00
public class Client : IClientModel
{
2023-06-03 01:27:48 +04:00
[DataMember]
2023-05-14 11:29:13 +04:00
public int Id { get; private set; }
[Required]
2023-06-03 01:27:48 +04:00
[DataMember]
2023-05-14 11:29:13 +04:00
public string ClientFIO { get; set; } = string.Empty;
[Required]
2023-06-03 01:27:48 +04:00
[DataMember]
2023-05-14 11:29:13 +04:00
public string Email { get; set; } = string.Empty;
[Required]
2023-06-03 01:27:48 +04:00
[DataMember]
2023-05-14 11:29:13 +04:00
public string Password { get; set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public static Client Create(ClientViewModel model)
{
return new Client
{
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
};
}
}