PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenDatabaseImplement/Models/Tableware.cs
2023-05-19 03:39:58 +04:00

60 lines
1.6 KiB
C#

using CanteenDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CanteenContracts.BindingModels;
using CanteenContracts.View;
using NHibernate.Mapping;
namespace CanteenDatabaseImplement.Models
{
public class Tableware : ITablewareModel
{
public int Id { get; private set; }
[Required]
public int VisitorId { get; private set; }
[Required]
public string TablewareName { get; private set; } = string.Empty;
[ForeignKey("TablewareId")]
public virtual List<OrderTableware> Orders { get; set; } = new();
public virtual Visitor Visitor { get; set; }
public static Tableware? Create(TablewareBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
VisitorId = model.VisitorId,
TablewareName = model.TablewareName
};
}
public void Update(TablewareBindingModel model)
{
if (model == null)
{
return;
}
Id = model.Id;
VisitorId = model.VisitorId;
TablewareName = model.TablewareName;
}
public TablewareViewModel GetViewModel => new()
{
Id = Id,
VisitorId = VisitorId,
TablewareName = TablewareName
};
}
}