using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.ViewModels; using SecuritySystemDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SecuritySystemDatabaseImplement.Models { public class Sensor : ISensorModel { public int Id { get; private set; } [Required] public string SensorName { get; private set; } = string.Empty; [Required] public double Cost { get; set; } //для реализации связи многие ко многим с изделиями [ForeignKey("SensorId")] public virtual List SecureSensors { get; set; } = new(); public static Sensor? Create(SensorBindingModel model) { if(model == null) { return null; } return new Sensor() { Id = model.Id, SensorName = model.SensorName, Cost = model.Cost }; } public static Sensor Create(SensorViewModel model) { return new Sensor { Id = model.Id, SensorName = model.SensorName, Cost = model.Cost }; } public void Update(SensorBindingModel model) { if(model == null) { return; } SensorName = model.SensorName; Cost = model.Cost; } public SensorViewModel GetViewModel => new() { Id = Id, SensorName = SensorName, Cost = Cost }; } }