PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenDatabaseImplement/Models/Tableware.cs

63 lines
1.7 KiB
C#
Raw Normal View History

2023-04-07 18:58:07 +04:00
using CanteenDataModels.Models;
using System;
2023-04-07 10:55:40 +04:00
using System.Collections.Generic;
2023-04-07 18:58:07 +04:00
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
2023-04-07 10:55:40 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-04-09 00:34:25 +04:00
using CanteenContracts.BindingModels;
using CanteenContracts.View;
using NHibernate.Mapping;
2023-04-07 10:55:40 +04:00
namespace CanteenDatabaseImplement.Models
{
2023-04-07 18:58:07 +04:00
public class Tableware : ITablewareModel
2023-04-07 10:55:40 +04:00
{
2023-04-07 18:58:07 +04:00
public int Id { get; private set; }
[Required]
public int VisitorId { get; private set; }
[Required]
public string TablewareName { get; private set; } = string.Empty;
2023-05-14 22:24:37 +04:00
[Required]
public int Count { get; private set; }
2023-04-07 18:58:07 +04:00
[ForeignKey("TablewareId")]
2023-04-09 00:34:25 +04:00
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,
2023-05-14 22:24:37 +04:00
TablewareName = model.TablewareName,
Count = model.Count
2023-04-09 00:34:25 +04:00
};
}
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
};
2023-04-07 10:55:40 +04:00
}
}