110 lines
2.8 KiB
C#
110 lines
2.8 KiB
C#
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>
|
|
public class Driver : IDriverModel
|
|
{
|
|
/// <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()
|
|
{
|
|
Id = model.Id,
|
|
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()
|
|
{
|
|
Id = model.Id,
|
|
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
|
|
};
|
|
}
|
|
}
|