Pibd-22_Presnyakova.V.V_Jew.../JewelryStoreDatabaseImplement/Models/Implementer.cs

80 lines
2.1 KiB
C#
Raw Normal View History

2023-04-17 18:40:22 +04:00
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.ViewModels;
using JewelryStoreDataModels.Models;
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;
2023-05-02 14:50:43 +04:00
using System.Runtime.Serialization;
2023-04-17 18:40:22 +04:00
namespace JewelryStoreDatabaseImplement.Models
{
2023-05-02 14:50:43 +04:00
[DataContract]
public class Implementer : IImplementerModel
2023-04-17 18:40:22 +04:00
{
[Required]
2023-05-02 14:50:43 +04:00
[DataMember]
public string ImplementerFIO { get; private set; } = string.Empty;
2023-04-17 18:40:22 +04:00
[Required]
2023-05-02 14:50:43 +04:00
[DataMember]
public string Password { get; private set; } = string.Empty;
2023-04-17 18:40:22 +04:00
[Required]
2023-05-02 14:50:43 +04:00
[DataMember]
public int WorkExperience { get; private set; }
2023-04-17 18:40:22 +04:00
[Required]
2023-05-02 14:50:43 +04:00
[DataMember]
public int Qualification { get; private set; }
2023-04-17 18:40:22 +04:00
2023-05-02 14:50:43 +04:00
[DataMember]
public int Id { get; private set; }
2023-04-17 18:40:22 +04:00
[ForeignKey("ImplementerId")]
public virtual List<Order> Orders { get; private 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
};
}
}