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.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace RouteGuideDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сущность "Водитель"
|
|
|
|
|
/// </summary>
|
2024-04-23 19:38:25 +04:00
|
|
|
|
public class Driver : IDriverModel<int>
|
2024-04-02 02:15:17 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Идентификатор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ФИО водителя
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Required]
|
|
|
|
|
public string FullName { get; private set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Номер телефона водителя
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Required]
|
|
|
|
|
public string Phone { get; private set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Опыт работы водителя
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? Experience { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание модели
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static Driver? Create(DriverBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Driver()
|
|
|
|
|
{
|
2024-04-23 19:38:25 +04:00
|
|
|
|
Id = (int)model.Id,
|
2024-04-02 02:15:17 +04:00
|
|
|
|
FullName = model.FullName,
|
|
|
|
|
Phone = model.Phone,
|
|
|
|
|
Experience = model.Experience
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание модели
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static Driver? Create(DriverViewModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Driver()
|
|
|
|
|
{
|
2024-04-23 19:38:25 +04:00
|
|
|
|
Id = (int)model.Id,
|
2024-04-02 02:15:17 +04:00
|
|
|
|
FullName = model.FullName,
|
|
|
|
|
Phone = model.Phone,
|
|
|
|
|
Experience = model.Experience
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение модели
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void Update(DriverBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FullName = model.FullName;
|
|
|
|
|
Phone = model.Phone;
|
|
|
|
|
Experience = model.Experience;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение модели
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DriverViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
FullName = FullName,
|
|
|
|
|
Phone = Phone,
|
|
|
|
|
Experience = Experience
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|