using RouteGuideContracts.BindingModels;
using RouteGuideContracts.ViewModels;
using RouteGuideDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RouteGuideDatabaseImplement.Models
{
///
/// Сущность "Водитель"
///
public class Driver : IDriverModel
{
///
/// Идентификатор
///
public int Id { get; private set; }
///
/// ФИО водителя
///
[Required]
public string FullName { get; private set; } = string.Empty;
///
/// Номер телефона водителя
///
[Required]
public string Phone { get; private set; } = string.Empty;
///
/// Опыт работы водителя
///
public int? Experience { get; private set; }
///
/// Создание модели
///
///
///
public static Driver? Create(DriverBindingModel model)
{
if (model == null)
{
return null;
}
return new Driver()
{
Id = model.Id,
FullName = model.FullName,
Phone = model.Phone,
Experience = model.Experience
};
}
///
/// Создание модели
///
///
///
public static Driver? Create(DriverViewModel model)
{
if (model == null)
{
return null;
}
return new Driver()
{
Id = model.Id,
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
};
}
}