PIbd-22_Aleikin_A.M._Confec.../Confectionery/ConfectioneryDatabaseImplement/Models/Implementer.cs

88 lines
2.5 KiB
C#
Raw Permalink Normal View History

2023-05-03 23:15:51 +04:00
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
2023-05-04 23:45:15 +04:00
using System.Runtime.Serialization;
2023-05-03 23:15:51 +04:00
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryDatabaseImplement.Models
{
2023-05-04 23:45:15 +04:00
[DataContract]
2023-05-03 23:15:51 +04:00
public class Implementer : IImplementerModel
{
[Required]
2023-05-04 23:45:15 +04:00
[DataMember]
2023-05-03 23:15:51 +04:00
public string ImplementerFIO { get; set; } = string.Empty;
[Required]
2023-05-04 23:45:15 +04:00
[DataMember]
2023-05-03 23:15:51 +04:00
public string Password { get; set; } = string.Empty;
[Required]
2023-05-04 23:45:15 +04:00
[DataMember]
2023-05-03 23:15:51 +04:00
public int WorkExperience { get; set; }
[Required]
2023-05-04 23:45:15 +04:00
[DataMember]
2023-05-03 23:15:51 +04:00
public int Qualification { get; set; }
[Required]
2023-05-04 23:45:15 +04:00
[DataMember]
2023-05-03 23:15:51 +04:00
public int Id { get; set; }
[ForeignKey("ImplementerId")]
public virtual List<Order> Orders { get; set; } = new();
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new Implementer()
{
Id = model.Id,
ImplementerFIO = model.ImplementerFIO,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification
};
}
public static Implementer Create(ImplementerViewModel model)
{
return new Implementer
{
Id = model.Id,
ImplementerFIO = model.ImplementerFIO,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
ImplementerFIO = model.ImplementerFIO;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
ImplementerFIO = ImplementerFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification
};
}
}