PIbd-23_Elatomtsev_L.K._Con.../Confectionery/ConfectioneryDatabaseImplement/Models/Implementer.cs

63 lines
2.0 KiB
C#
Raw Permalink Normal View History

2024-05-08 15:04:44 +04:00
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
2024-05-22 14:38:56 +04:00
using System.Runtime.Serialization;
2024-05-08 15:04:44 +04:00
namespace ConfectioneryDatabaseImplement.Models
{
2024-05-22 14:38:56 +04:00
[DataContract]
2024-05-08 15:04:44 +04:00
public class Implementer : IImplementerModel
{
2024-05-22 14:38:56 +04:00
[DataMember]
2024-05-08 15:04:44 +04:00
public int Id { get; private set; }
2024-05-22 14:38:56 +04:00
[DataMember]
2024-05-08 15:04:44 +04:00
[Required]
public string ImplementerFIO { get; private set; } = string.Empty;
2024-05-22 14:38:56 +04:00
[DataMember]
2024-05-08 15:04:44 +04:00
[Required]
public string Password { get; set; } = string.Empty;
2024-05-22 14:38:56 +04:00
[DataMember]
2024-05-08 15:04:44 +04:00
[Required]
public int Qualification { get; set; } = 0;
2024-05-22 14:38:56 +04:00
[DataMember]
2024-05-08 15:04:44 +04:00
[Required]
public int WorkExperience { get; set; } = 0;
[ForeignKey("ImplementerId")]
public virtual List<Order> Orders { get; set; } = new();
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Password = model.Password,
Qualification = model.Qualification,
ImplementerFIO = model.ImplementerFIO,
WorkExperience = model.WorkExperience,
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
Password = model.Password;
Qualification = model.Qualification;
ImplementerFIO = model.ImplementerFIO;
WorkExperience = model.WorkExperience;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Password = Password,
Qualification = Qualification,
ImplementerFIO = ImplementerFIO,
WorkExperience = WorkExperience,
};
}
}