Coursework_ComputerStore_Li.../ComputerStoreDatabaseImplement/Models/Seller.cs

67 lines
2.0 KiB
C#
Raw Normal View History

2023-04-07 20:46:13 +04:00
using ComputerStoreContracts.BindingModels;
using ComputerStoreContracts.ViewModels;
using ComputerStoreDataModels.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;
namespace ComputerStoreDatabaseImplement.Models
{
public class Seller : ISellerModel
{
public int ID { get; private set; }
[Required]
public string Username { get; private set; } = string.Empty;
[Required]
public string Password { get; private set; } = string.Empty;
public string? FirstName { get; private set; } = string.Empty;
public string? LastName { get; private set; } = string.Empty;
public string? MiddleName { get; private set; } = string.Empty;
[ForeignKey("OrderID")]
public virtual List<Order> Orders { get; set; } = new();
public static Seller? Create(SellerBindingModel? model)
{
if (model == null)
{
return null;
}
return new Seller()
{
ID = model.ID,
Username = model.Username,
Password = model.Password,
FirstName = model.FirstName,
LastName = model.LastName,
MiddleName = model.MiddleName
};
}
public void Update(SellerBindingModel? model)
{
if (model == null) { return; }
Username = model.Username;
Password = model.Password;
FirstName = model.FirstName;
LastName = model.LastName;
MiddleName = model.MiddleName;
}
public SellerViewModel GetViewModel => new()
{
ID = ID,
Username = Username,
Password = Password,
FirstName = FirstName,
LastName = LastName,
MiddleName = MiddleName
};
}
}