ISEbd-22_Baygulov_A.A._Sush.../SushiBar/SushiBarDatabaseImplement/Client.cs

85 lines
2.2 KiB
C#
Raw Normal View History

2024-05-03 19:28:58 +04:00
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
2024-06-01 17:37:58 +04:00
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2024-05-03 19:28:58 +04:00
using System.Linq;
2024-06-01 17:37:58 +04:00
using System.Runtime.Serialization;
2024-05-03 19:28:58 +04:00
using System.Text;
using System.Threading.Tasks;
2024-06-01 17:37:58 +04:00
namespace SushiBarDatabaseImplement.Models
2024-05-03 19:28:58 +04:00
{
2024-06-01 17:37:58 +04:00
[DataContract]
public class Client : IClientModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
[Required]
public string ClientFIO { get; set; } = string.Empty;
[DataMember]
[Required]
public string Email { get; set; } = string.Empty;
2024-05-03 19:28:58 +04:00
2024-06-01 17:37:58 +04:00
[DataMember]
[Required]
public string Password { get; set; } = string.Empty;
2024-05-03 19:28:58 +04:00
2024-06-01 17:37:58 +04:00
[ForeignKey("ClientId")]
2024-06-01 16:27:44 +04:00
public virtual List<Order> ClientOrders { get; set; } = new();
2024-05-03 19:28:58 +04:00
2024-06-01 16:27:44 +04:00
[ForeignKey("ClientId")]
public virtual List<MessageInfo> ClientMessages { get; set; } = new();
2024-06-01 17:37:58 +04:00
2024-06-01 16:27:44 +04:00
public static Client? Create(ClientBindingModel model)
{
2024-06-01 17:37:58 +04:00
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
2024-05-03 19:28:58 +04:00
2024-06-01 17:37:58 +04:00
public static Client Create(ClientViewModel model)
{
return new Client
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
2024-06-01 17:37:58 +04:00
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
2024-06-01 17:37:58 +04:00
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
}
2024-05-03 19:28:58 +04:00
}