Pibd-22_Presnyakova.V.V_Jew.../JewelryStoreDatabaseImplement/Models/Client.cs

79 lines
2.1 KiB
C#
Raw Normal View History

2023-04-01 20:39:14 +04:00
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.ViewModels;
using JewelryStoreDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-05-02 14:50:43 +04:00
using System.Runtime.Serialization;
2023-04-01 20:39:14 +04:00
namespace JewelryStoreDatabaseImplement.Models
{
2023-05-02 14:50:43 +04:00
[DataContract]
public class Client : IClientModel
2023-04-01 20:39:14 +04:00
{
2023-05-02 14:50:43 +04:00
[DataMember]
public int Id { get; private set; }
2023-04-01 20:39:14 +04:00
[Required]
2023-05-02 14:50:43 +04:00
[DataMember]
public string ClientFIO { get; set; } = string.Empty;
2023-04-01 20:39:14 +04:00
[Required]
2023-05-02 14:50:43 +04:00
[DataMember]
public string Email { get; set; } = string.Empty;
2023-04-01 20:39:14 +04:00
[Required]
2023-05-02 14:50:43 +04:00
[DataMember]
public string Password { get; set; } = string.Empty;
2023-04-01 20:39:14 +04:00
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
2023-04-30 19:37:01 +04:00
[ForeignKey("ClientId")]
public virtual List<Message> Messages { get; set; } = new();
public static Client? Create(ClientBindingModel model)
2023-04-01 20:39:14 +04:00
{
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
};
}
}