Модельки
This commit is contained in:
parent
363db785d3
commit
c61315f4a1
@ -0,0 +1,39 @@
|
||||
using NorthBridgeContracts.Enums;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class ComponentDataModel(string id, string componentName, ComponentType componentType, string manufacturerId, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string ComponentName { get; private set; } = componentName;
|
||||
|
||||
public ComponentType ComponentType { get; private set; } = componentType;
|
||||
|
||||
public string ManufacturerId { get; private set; } = manufacturerId;
|
||||
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (ComponentName.IsEmpty())
|
||||
throw new ValidationException("Field ComponentName is empty");
|
||||
if (ComponentType == ComponentType.None)
|
||||
throw new ValidationException("Field ComponentType is empty");
|
||||
if (ManufacturerId.IsEmpty())
|
||||
throw new ValidationException("Field ManufacturerId is empty");
|
||||
if (!ManufacturerId.IsGuid())
|
||||
throw new ValidationException("The value in the field ManufacturerId is not a unique identifier");
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class ComponentHistoryDataModel(string componentId, double oldPrice) : IValidation
|
||||
{
|
||||
public string ComponentId { get; private set; } = componentId;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice; // олд спайс
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow; // дата изменения цены
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (ComponentId.IsEmpty())
|
||||
throw new ValidationException("Field ComponentId is empty");
|
||||
if (!ComponentId.IsGuid())
|
||||
throw new ValidationException("The value in the field ComponentId is not a unique identifier");
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
using System.Text.RegularExpressions;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class CustomerDataModel(string id, string fio, string phone, string email, double discountSize) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public string Phone { get; private set; } = phone;
|
||||
public string Email { get; private set; } = email;
|
||||
public double DiscountSize { get; private set; } = discountSize;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty");
|
||||
if (Phone.IsEmpty()) throw new ValidationException("Field Phone is empty");
|
||||
|
||||
var phoneRegex = new Regex(@"^\+7\d{10}$");
|
||||
if (!phoneRegex.IsMatch(Phone)) throw new ValidationException("Invalid phone format");
|
||||
|
||||
if (Email.IsEmpty() || !Email.Contains("@")) throw new ValidationException("Invalid email format");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class ManufacturerDataModel(string id, string manufacturerName, string?
|
||||
prevManufacturerName, string? prevPrevManufacturerName) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string ManufacturerName { get; private set; } = manufacturerName;
|
||||
public string? PrevManufacturerName { get; private set; } =
|
||||
prevManufacturerName;
|
||||
public string? PrevPrevManufacturerName { get; private set; } =
|
||||
prevPrevManufacturerName;
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (ManufacturerName.IsEmpty())
|
||||
throw new ValidationException("Field ManufacturerName isempty");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
using NorthBridgeContracts.Enums;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string PostId { get; private set; } = postId;
|
||||
|
||||
public string PostName { get; private set; } = postName;
|
||||
|
||||
public PostType PostType { get; private set; } = postType;
|
||||
|
||||
public double Salary { get; private set; } = salary;
|
||||
|
||||
public bool IsActual { get; private set; } = isActual;
|
||||
|
||||
/// <summary>
|
||||
/// Когда эта запись была изменена
|
||||
/// </summary>
|
||||
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
if (PostName.IsEmpty())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
|
||||
{
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
|
||||
public double Salary { get; private set; } = workerSalary;
|
||||
public void Validate()
|
||||
{
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using NorthBridgeContracts.Enums;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class SaleDataModel(string id, string workerId, string? customerId, double sum, DiscountType discountType, double discount, bool isCancel, List<SaleProductDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
public string? CustomerId { get; private set; } = customerId;
|
||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||
public double Sum { get; private set; } = sum;
|
||||
public DiscountType DiscountType { get; private set; } = discountType;
|
||||
public double Discount { get; private set; } = discount;
|
||||
public bool IsCancel { get; private set; } = isCancel;
|
||||
public List<SaleProductDataModel> Products { get; private set; } =
|
||||
products;
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
if (!CustomerId?.IsGuid() ?? !CustomerId?.IsEmpty() ?? false)
|
||||
throw new ValidationException("The value in the field BuyerId is not a unique identifier");
|
||||
if (Sum <= 0)
|
||||
throw new ValidationException("Field Sum is less than or equal to 0");
|
||||
if ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class SaleProductDataModel(string saleId, string productId, int count) : IValidation
|
||||
{
|
||||
public string SaleId { get; private set; } = saleId;
|
||||
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SaleId.IsEmpty())
|
||||
throw new ValidationException("Field SaleId is empty");
|
||||
if (!SaleId.IsGuid())
|
||||
throw new ValidationException("The value in the field SaleId is not a unique identifier");
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fio;
|
||||
|
||||
public string PostId { get; private set; } = postId;
|
||||
|
||||
public DateTime BirthDate { get; private set; } = birthDate;
|
||||
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted; // признак уволился или нет
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
|
||||
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
||||
if (EmploymentDate.Date < BirthDate.Date)
|
||||
throw new ValidationException("The date of employment caanot be less than the date of birth");
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
namespace NorthBridgeContracts.Enums;
|
||||
|
||||
public enum ComponentType
|
||||
{
|
||||
None = 0, // Не указано
|
||||
Motherboard = 1, // Мать
|
||||
Processor = 2, // Процессор
|
||||
Ram = 3, // Оперативка
|
||||
PowerUnit = 4, // БП
|
||||
GraphicsCard = 5, // Видюха
|
||||
SVO = 6, // Система Воздушного Охлаждения (кулеры)
|
||||
SJO = 7, // Система ЖИДкостного Охлаждения
|
||||
Case = 8, // Кейс
|
||||
Storage = 9, // Накопитель (SSD и HDD)
|
||||
Monitor = 10, // Монитор
|
||||
Peripheral = 11 // Периферия (мышки клавы уши, крч I/O Devices)
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
namespace NorthBridgeContracts.Enums;
|
||||
|
||||
|
||||
[Flags]
|
||||
public enum DiscountType
|
||||
{
|
||||
None = 0, // Без скидки
|
||||
SeasonalSale = 1, // Сезонная распродажа
|
||||
LoyaltyProgram = 2, // Программа ноу лоялти ноу роялти
|
||||
BundleDiscount = 4, // Скидка за комплект
|
||||
PromoCode = 8 // Скидка по промокоду
|
||||
}
|
10
NorthBridgeProject/NorthBridgeContracts/Enums/PostType.cs
Normal file
10
NorthBridgeProject/NorthBridgeContracts/Enums/PostType.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace NorthBridgeContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0, // Не указано
|
||||
Manager = 1, // Менеджер (административная должность)
|
||||
SalesSpecialist = 2, // Специалист по продажам
|
||||
TechnicalSpecialist = 3, // Технический специалист
|
||||
StockmanDNS = 4 // Кладовщик
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
namespace NorthBridgeContracts.Exceptions;
|
||||
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
namespace NorthBridgeContracts.Extensions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static bool IsEmpty(this string str)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
public static bool IsGuid(this string str)
|
||||
{
|
||||
return Guid.TryParse(str, out _);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace NorthBridgeContracts.Infrastructure;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user