using RouteGuideContracts.BindingModels;
using RouteGuideContracts.ViewModels;
using RouteGuideDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace RouteGuideDatabaseImplement.Models
{
///
/// Сущность "Остановка"
///
public class Stop : IStopModel
{
///
/// Идентификатор
///
public int Id { get; private set; }
///
/// Название остановки
///
[Required]
public string Name { get; private set; } = string.Empty;
///
/// Название улицы
///
[Required]
public string Street { get; private set; } = string.Empty;
///
/// Номер дома
///
[Required]
public int Number { get; private set; }
///
/// Создание модели
///
///
///
public static Stop? Create(StopBindingModel model)
{
if (model == null)
{
return null;
}
return new Stop()
{
Id = (int)model.Id,
Name = model.Name,
Street = model.Street,
Number = model.Number
};
}
///
/// Создание модели
///
///
///
public static Stop? Create(StopViewModel model)
{
if (model == null)
{
return null;
}
return new Stop()
{
Id = (int)model.Id,
Name = model.Name,
Street = model.Street,
Number = model.Number
};
}
///
/// Изменение модели
///
///
public void Update(StopBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Street = model.Street;
Number = model.Number;
}
///
/// Получение модели
///
public StopViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Street = Street,
Number = Number
};
}
}