From 2643f53e0b1483f967e90999bb9467602b55b417 Mon Sep 17 00:00:00 2001 From: dex_moth Date: Tue, 30 Apr 2024 17:16:45 +0400 Subject: [PATCH] Vendor --- .../Models/Vendor.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Vendor.cs diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Vendor.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Vendor.cs new file mode 100644 index 0000000..bc9567d --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Vendor.cs @@ -0,0 +1,52 @@ +using ComputerHardwareStoreContracts.BindingModels; +using ComputerHardwareStoreContracts.ViewModels; +using ComputerHardwareStoreDataModels.Models; +using System.ComponentModel.DataAnnotations; + +namespace ComputerHardwareStoreDatabaseImplement.Models +{ + public class Vendor : IVendorModel + { + public int Id { get; private set; } + [Required] + public string Name { get; private set; } = string.Empty; + [Required] + + public string Login { get; private set; } = string.Empty; + [Required] + + public string Password { get; private set; } = string.Empty; + + public static Vendor? Create(ComputerHardwareStoreDBContext context, VendorBindingModel model) + { + if (model == null) + { + return null; + } + return new Vendor() + { + Id = model.Id, + Name = model.Name, + Login = model.Login, + Password = model.Password, + }; + } + public void Update(VendorBindingModel model) + { + if (model == null) + { + return; + } + Name = string.IsNullOrEmpty(model.Name) ? Name : model.Name; + Password = string.IsNullOrEmpty(model.Password) ? Password : model.Password; + } + + public VendorViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Login = Login, + Password = Password + }; + } +}