ISEbd-21_Melnikov_I.O._CarS.../CarService/CarServiceDatabase/Models/Customer.cs

61 lines
1.4 KiB
C#
Raw Normal View History

using CarServiceContracts.BindingModels;
using CarServiceContracts.Models;
using CarServiceContracts.ViewModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace CarServiceDatabase.Models
{
public class Customer : ICustomerModel
{
public int Id { get; private set; }
[Required]
public string Login { get; private set; } = string.Empty;
[Required]
public string Password { get; private set; } = string.Empty;
[Required]
public string Name { get; private set; } = string.Empty;
[Required]
public string Surname { get; private set; } = string.Empty;
/// <summary>
/// Транспортные средства
/// </summary>
[ForeignKey("CustomerId")]
public virtual List<Vehicle> Vehicles { get; set; } = new();
public static Customer? Create(CustomerBindingModel? model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Login = model.Login,
Password = model.Password,
Name = model.Name,
Surname = model.Surname
};
}
public void Update(CustomerBindingModel? model)
{
if (model == null)
{
return;
}
Login = model.Login;
Password = model.Password;
Name = model.Name;
Surname = model.Surname;
}
public CustomerViewModel GetViewModel => new()
{
Id = Id,
Login = Login,
Password = Password,
Name = Name,
Surname = Surname
};
}
}