DB/TransportGuideDatabaseImplements/Models/Stop.cs

59 lines
1.1 KiB
C#

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TransportGuideContracts.BindingModels;
using TransportGuideContracts.ViewModels;
using TransportGuideDataModels.Models;
namespace TransportGuideDatabaseImplements.Models
{
public class Stop : IStopModel
{
public int Id { get; private set; }
[Required]
public string Name { get; private set; } = string.Empty;
[ForeignKey("StopId")]
public virtual List<StopRoute> StopRoutes { get; set; } = new();
public static Stop? Create(StopBindingModel model)
{
if (model == null)
{
return null;
}
return new Stop()
{
Id = model.Id,
Name = model.Name,
};
}
public static Stop Create(StopViewModel model)
{
return new Stop
{
Id = model.Id,
Name = model.Name,
};
}
public void Update(StopBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public StopViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
};
}
}