PIBD-21_Lobashov_I_D_Travel.../TravelCompany/TravelCompanyDatabaseImplement/Models/Client.cs

81 lines
1.6 KiB
C#
Raw Normal View History

2024-04-18 16:34:54 +04:00
using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.ViewModels;
using TravelCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2024-05-18 14:59:42 +04:00
using System.Runtime.Serialization;
2024-04-18 16:34:54 +04:00
namespace TravelCompanyDatabaseImplement.Models
{
2024-05-18 14:59:42 +04:00
[DataContract]
public class Client : IClientModel
2024-04-18 16:34:54 +04:00
{
2024-05-18 14:59:42 +04:00
[DataMember]
public int Id { get; private set; }
2024-04-18 16:34:54 +04:00
2024-05-18 14:59:42 +04:00
[DataMember]
[Required]
2024-04-18 16:34:54 +04:00
public string ClientFIO { get; set; } = string.Empty;
2024-05-18 14:59:42 +04:00
[DataMember]
[Required]
2024-04-18 16:34:54 +04:00
public string Email { get; set; } = string.Empty;
2024-05-18 14:59:42 +04:00
[DataMember]
[Required]
2024-04-18 16:34:54 +04:00
public string Password { get; set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public static Client Create(ClientViewModel model)
{
return new Client
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
}
}