112 lines
2.7 KiB
C#
112 lines
2.7 KiB
C#
|
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
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Сущность "Остановка"
|
|||
|
/// </summary>
|
|||
|
public class Stop : IStopModel
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Идентификатор
|
|||
|
/// </summary>
|
|||
|
public int Id { get; private set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Название остановки
|
|||
|
/// </summary>
|
|||
|
[Required]
|
|||
|
public string Name { get; private set; } = string.Empty;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Название улицы
|
|||
|
/// </summary>
|
|||
|
[Required]
|
|||
|
public string Street { get; private set; } = string.Empty;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Номер дома
|
|||
|
/// </summary>
|
|||
|
[Required]
|
|||
|
public int Number { get; private set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Создание модели
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static Stop? Create(StopBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
return new Stop()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
Name = model.Name,
|
|||
|
Street = model.Street,
|
|||
|
Number = model.Number
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Создание модели
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static Stop? Create(StopViewModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
return new Stop()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
Name = model.Name,
|
|||
|
Street = model.Street,
|
|||
|
Number = model.Number
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Изменение модели
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
public void Update(StopBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Name = model.Name;
|
|||
|
Street = model.Street;
|
|||
|
Number = model.Number;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Получение модели
|
|||
|
/// </summary>
|
|||
|
public StopViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
Name = Name,
|
|||
|
Street = Street,
|
|||
|
Number = Number
|
|||
|
};
|
|||
|
}
|
|||
|
}
|