using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using RouteGuideDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RouteGuideContracts.BindingModels;
using RouteGuideContracts.ViewModels;
namespace RouteGuideMongoDBImplement.Models
{
///
/// Сущность "Водитель"
///
public class Driver : IDriverModel
{
///
/// Идентификатор
///
[BsonId]
[BsonElement("_id")]
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; private set; }
///
/// ФИО водителя
///
[BsonRequired]
public string FullName { get; private set; } = string.Empty;
///
/// Номер телефона водителя
///
[BsonRequired]
public string Phone { get; private set; } = string.Empty;
///
/// Опыт работы водителя
///
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public int? Experience { get; private set; }
///
/// Создание модели
///
///
///
public static Driver? Create(DriverBindingModel model)
{
if (model == null)
{
return null;
}
return new Driver()
{
FullName = model.FullName,
Phone = model.Phone,
Experience = model.Experience
};
}
///
/// Создание модели
///
///
///
public static Driver? Create(DriverViewModel model)
{
if (model == null)
{
return null;
}
return new Driver()
{
FullName = model.FullName,
Phone = model.Phone,
Experience = model.Experience
};
}
///
/// Изменение модели
///
///
public void Update(DriverBindingModel model)
{
if (model == null)
{
return;
}
FullName = model.FullName;
Phone = model.Phone;
Experience = model.Experience;
}
///
/// Получение модели
///
public DriverViewModel GetViewModel => new()
{
Id = Id!,
FullName = FullName,
Phone = Phone,
Experience = Experience
};
}
}