SUBD/Sushi/SushiDatabaseImplement/Models/Client.cs

57 lines
1.4 KiB
C#

using SushiContracts.BindingModels;
using SushiContracts.ViewModels;
using SushiDataModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using SushiShopDatabaseImplement.Models;
namespace SushiDatabaseImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
[Required]
public string ClientName { get; private set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Order> Order { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientName = model.ClientName,
};
}
public static Client Create(ClientViewModel model)
{
return new Client()
{
Id = model.Id,
ClientName = model.ClientName,
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
ClientName = model.ClientName;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientName = ClientName
};
}
}