using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using TransportCompanyContracts.BindingModels; using TransportCompanyContracts.ViewModels; using TransportCompanyDataModels.Models; namespace TransportCompanyDatabaseImplement.Models { public class Point : IPointModel { public int Id { get; private set; } [Required] public string PointName { get; private set; } = string.Empty; [Required] public string Address { get; private set; } = string.Empty; [ForeignKey("PointToId")] public virtual List TransportationsTo { get; set; } = new(); [ForeignKey("PointFromId")] public virtual List TransportationsFrom { get; set; } = new(); public static Point? Create(PointBindingModel model) { if (model == null) { return null; } return new Point() { Id = model.Id, PointName = model.PointName, Address = model.Address }; } public static Point Create(PointViewModel model) { return new Point { Id = model.Id, PointName = model.PointName, Address = model.Address }; } public void Update(PointBindingModel model) { if (model == null) { return; } PointName = model.PointName; Address = model.Address; } public PointViewModel GetViewModel => new() { Id = Id, PointName = PointName, Address = Address }; } }