using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using RouteGuideContracts.BindingModels;
using RouteGuideContracts.ViewModels;
using RouteGuideDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RouteGuideMongoDBImplement.Models
{
///
/// Сущность "Остановка"
///
public class Stop : IStopModel
{
///
/// Идентификатор
///
[BsonId]
[BsonElement("_id")]
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; private set; }
///
/// Название остановки
///
[BsonRequired]
public string Name { get; private set; } = string.Empty;
///
/// Название улицы
///
[BsonRequired]
public string Street { get; private set; } = string.Empty;
///
/// Номер дома
///
[BsonRequired]
public int Number { get; private set; }
///
/// Создание модели
///
///
///
public static Stop? Create(StopBindingModel model)
{
if (model == null)
{
return null;
}
return new Stop()
{
Name = model.Name,
Street = model.Street,
Number = model.Number
};
}
///
/// Создание модели
///
///
///
public static Stop? Create(StopViewModel model)
{
if (model == null)
{
return null;
}
return new Stop()
{
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
};
}
}