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

65 lines
1.7 KiB
C#
Raw Normal View History

2023-04-07 23:35:33 +04:00
using CanteenContracts.BindingModels;
using CanteenContracts.View;
using CanteenDataModels.Models;
2023-04-07 10:55:40 +04:00
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanteenDatabaseImplement.Models
{
public class Cook : ICookModel
{
2023-04-07 18:58:07 +04:00
public int Id { get; private set; }
[Required]
public int ManagerId { get; private set; }
2023-04-07 10:55:40 +04:00
[Required]
2023-04-07 23:35:33 +04:00
public string FIO { get; private set; } = string.Empty;
2023-04-07 10:55:40 +04:00
[Required]
public string Position { get; private set; } = string.Empty;
[ForeignKey("CookId")]
2023-05-20 12:11:48 +04:00
public virtual List<ProductCook> Products { get; set; }
2023-04-09 00:34:25 +04:00
[ForeignKey("CookId")]
2023-05-20 12:11:48 +04:00
public virtual List<OrderCook> Orders { get; set; }
2023-04-09 00:34:25 +04:00
public virtual Manager Manager { get; set; }
2023-04-07 23:35:33 +04:00
public static Cook Create(CookBindingModel model)
{
if (model == null)
{
return null;
}
return new Cook
{
Id = model.Id,
ManagerId = model.ManagerId,
FIO = model.FIO,
Position = model.Position
};
}
public void Update(CookBindingModel model)
{
if (model == null)
{
return;
}
FIO = model.FIO;
Position = model.Position;
}
public CookViewModel GetViewModel => new CookViewModel
{
Id = Id,
ManagerId = ManagerId,
FIO = FIO,
2023-06-14 22:47:30 +04:00
Position = Position,
2023-04-07 23:35:33 +04:00
};
2023-04-07 10:55:40 +04:00
}
}