SUBD/Sushi/SushiDatabaseImplement/Models/Employee.cs

75 lines
2.2 KiB
C#

using SushiContracts.BindingModels;
using SushiContracts.BusinessLogicContracts;
using SushiContracts.ViewModels;
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 SushiDataModels;
using SushiShopDatabaseImplement.Models;
namespace SushiDatabaseImplement.Models
{
public class Employee : IEmployeeModel
{
public int Id { get; private set; }
[Required]
public string EmployeeName { get; private set; } = string.Empty;
[Required]
public long EmployeePhone { get; private set; }
[Required]
public string EmployeePosition { get; private set; } = string.Empty;
[ForeignKey("EmployeeId")]
public virtual List<Order> Order { get; set; } = new();
public static Employee? Create(EmployeeBindingModel model)
{
if (model == null)
{
return null;
}
return new Employee()
{
Id = model.Id,
EmployeeName = model.EmployeeName,
EmployeePhone = model.EmployeePhone,
EmployeePosition = model.EmployeePosition
};
}
public static Employee Create(EmployeeViewModel model)
{
return new Employee()
{
Id = model.Id,
EmployeeName = model.EmployeeName,
EmployeePhone = model.EmployeePhone,
EmployeePosition = model.EmployeePosition
};
}
public void Update(EmployeeBindingModel model)
{
if (model == null)
{
return;
}
EmployeeName = model.EmployeeName;
EmployeePhone = model.EmployeePhone;
EmployeePosition = model.EmployeePosition;
}
public EmployeeViewModel GetViewModel => new()
{
Id = Id,
EmployeeName = EmployeeName,
EmployeePhone = EmployeePhone,
EmployeePosition = EmployeePosition
};
}
}