PIbd-22_Smirnov_A.A._Securi.../SecuritySystem/SecuritySystemDatabaseImplement/Models/Sensor.cs
2024-05-07 17:56:47 +04:00

72 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<SecureSensor> 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
};
}
}