PIbd-21_MasenkinMS_SUBD_Rou.../RouteGuide/RouteGuideDatabaseImplement/Models/Stop.cs

112 lines
2.8 KiB
C#
Raw Permalink Normal View History

2024-04-02 02:15:17 +04:00
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>
2024-04-23 19:38:25 +04:00
public class Stop : IStopModel<int>
2024-04-02 02:15:17 +04:00
{
/// <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()
{
2024-04-23 19:38:25 +04:00
Id = (int)model.Id,
2024-04-02 02:15:17 +04:00
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()
{
2024-04-23 19:38:25 +04:00
Id = (int)model.Id,
2024-04-02 02:15:17 +04:00
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
};
}
}