PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenDatabaseImplement/Models/Tableware.cs
2023-05-14 22:24:37 +04:00

63 lines
1.7 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;
[Required]
public int Count { get; private set; }
[ForeignKey("TablewareId")]
public virtual List<Order> 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,
Count = model.Count
};
}
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
};
}
}