ISEbd-21_Tukaeva_A_A_School/School/SchoolDatabaseImplements/Models/Employee.cs

65 lines
1.6 KiB
C#
Raw Normal View History

using SchoolContracts.BindingModel;
using SchoolContracts.ViewModels;
using SchoolDataModels.Models;
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 SchoolDatabaseImplement.Models
{
public class Employee : IEmployeeModel
{
public int Id { get; set; }
[Required]
public string EmployeePhone { get; set; } = string.Empty;
[Required]
public string EmployeeEmail { get; set; } = string.Empty;
[Required]
public string EmployeePassword { get; set; } = string.Empty;
[Required]
public string EmployeeName { get; set; } = string.Empty;
[ForeignKey("EmployeeId")]
public virtual List<Lesson> Lessons { get; set; } = new();
public static Employee? Create(EmployeeBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
EmployeeName = model.EmployeeName,
EmployeeEmail = model.EmployeeEmail,
EmployeePassword = model.EmployeePassword,
EmployeePhone = model.EmployeePhone
};
}
public void Update(EmployeeBindingModel model)
{
if (model == null)
{
return;
}
EmployeeName = model.EmployeeName;
EmployeeEmail = model.EmployeeEmail;
EmployeePassword = model.EmployeePassword;
EmployeePhone = model.EmployeePhone;
}
public EmployeeViewModel GetViewModel => new()
{
Id = Id,
EmployeeName = EmployeeName,
EmployeeEmail = EmployeeEmail,
EmployeePassword = EmployeePassword,
EmployeePhone = EmployeePhone
};
}
}