Добавление моделей
This commit is contained in:
parent
929966de0a
commit
a70fb3710c
@ -0,0 +1,58 @@
|
||||
using North_Bridge_Contract.Infrastructure;
|
||||
using North_Bridge_Contract.Enums;
|
||||
using North_Bridge_Contract.Extentions;
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
|
||||
namespace North_Bridge_Contract.DataModels;
|
||||
|
||||
public class PostDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
|
||||
public string PostId { get; private set; }
|
||||
|
||||
public string PostName { get; private set; }
|
||||
|
||||
public PostType PostType { get; private set; }
|
||||
|
||||
public double Salary { get; private set; }
|
||||
|
||||
public bool IsActual { get; private set; }
|
||||
|
||||
public DateTime ChangeDate { get; private set; }
|
||||
|
||||
public PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate)
|
||||
{
|
||||
Id = id;
|
||||
PostId = postId;
|
||||
PostName = postName;
|
||||
PostType = postType;
|
||||
Salary = salary;
|
||||
IsActual = isActual;
|
||||
ChangeDate = 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 PostType is empty");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
using North_Bridge_Contract.Enums;
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
using North_Bridge_Contract.Extentions;
|
||||
using North_Bridge_Contract.Infrastructure;
|
||||
|
||||
namespace North_Bridge_Contract.DataModels;
|
||||
|
||||
public class ProductDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
|
||||
public string ProductName { get; private set; }
|
||||
|
||||
public ProductType ProductType { get; private set; }
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public bool IsDeleted { get; private set; }
|
||||
|
||||
public ProductDataModel(string id, string productName, ProductType productType, double price, bool isDeleted)
|
||||
{
|
||||
Id = id;
|
||||
ProductName = productName;
|
||||
ProductType = productType;
|
||||
Price = price;
|
||||
IsDeleted = 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 (ProductName.IsEmpty())
|
||||
throw new ValidationException("Field ProductName is empty");
|
||||
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field ProductType is empty");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
using North_Bridge_Contract.Extentions;
|
||||
using North_Bridge_Contract.Infrastructure;
|
||||
|
||||
namespace North_Bridge_Contract.DataModels;
|
||||
|
||||
public class ProductForSaleDataModel : IValidation
|
||||
{
|
||||
public string SaleId { get; private set; }
|
||||
|
||||
public string ProductId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public ProductForSaleDataModel(string saleId, string productId, int count)
|
||||
{
|
||||
SaleId = saleId;
|
||||
ProductId = productId;
|
||||
Count = 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,33 @@
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
using North_Bridge_Contract.Extentions;
|
||||
using North_Bridge_Contract.Infrastructure;
|
||||
|
||||
namespace North_Bridge_Contract.DataModels;
|
||||
|
||||
public class ProductHistoryDataModel : IValidation
|
||||
{
|
||||
public string ProductId { get; private set; }
|
||||
|
||||
public double OldPrice { get; private set; }
|
||||
|
||||
public DateTime ChangeDate { get; private set; }
|
||||
|
||||
public ProductHistoryDataModel(string productId, double oldPrice)
|
||||
{
|
||||
ProductId = productId;
|
||||
OldPrice = oldPrice;
|
||||
ChangeDate = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
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 (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
using North_Bridge_Contract.Extentions;
|
||||
using North_Bridge_Contract.Infrastructure;
|
||||
|
||||
namespace North_Bridge_Contract.DataModels;
|
||||
|
||||
public class SalaryDataModel : IValidation
|
||||
{
|
||||
public string WorkerId { get; private set; }
|
||||
|
||||
public DateTime SalaryDate { get; private set; }
|
||||
|
||||
public double Salary { get; private set; }
|
||||
|
||||
public SalaryDataModel(string workerId, DateTime salaryDate, double salary)
|
||||
{
|
||||
WorkerId = workerId;
|
||||
SalaryDate = salaryDate;
|
||||
Salary = salary;
|
||||
}
|
||||
|
||||
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,51 @@
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
using North_Bridge_Contract.Extentions;
|
||||
using North_Bridge_Contract.Infrastructure;
|
||||
|
||||
namespace North_Bridge_Contract.DataModels;
|
||||
|
||||
public class SaleDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
|
||||
public string WorkerId { get; private set; }
|
||||
|
||||
public DateTime SaleDate { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public bool IsCansel { get; private set; }
|
||||
|
||||
public List<ProductForSaleDataModel> Products { get; private set; }
|
||||
|
||||
public SaleDataModel(string id, string workerId, DateTime saleDate, double sum, bool isCansel, List<ProductForSaleDataModel> products)
|
||||
{
|
||||
Id = id;
|
||||
WorkerId = workerId;
|
||||
SaleDate = saleDate;
|
||||
Sum = sum;
|
||||
IsCansel = isCansel;
|
||||
Products = 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 (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,56 @@
|
||||
using North_Bridge_Contract.Exceptions;
|
||||
using North_Bridge_Contract.Extentions;
|
||||
using North_Bridge_Contract.Infrastructure;
|
||||
namespace North_Bridge_Contract.DataModels;
|
||||
|
||||
public class WorkerDataModelcs : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
|
||||
public string FIO { get; private set; }
|
||||
|
||||
public string PostId { get; private set; }
|
||||
|
||||
public DateTime BirthDate { get; private set; }
|
||||
|
||||
public DateTime EmploymentDate { get; private set; }
|
||||
|
||||
public bool IsDeleted { get; private set; }
|
||||
|
||||
public WorkerDataModelcs(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted)
|
||||
{
|
||||
Id = id;
|
||||
FIO = fio;
|
||||
PostId = postId;
|
||||
BirthDate = birthDate;
|
||||
EmploymentDate = employmentDate;
|
||||
IsDeleted = 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 cannot be less than the date of birth");
|
||||
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16) // EmploymentDate.Year - BirthDate.Year
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - { EmploymentDate.ToShortDateString() }, BirthDate - { BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
16
North_Bridge/North_Bridge_Contract/Enums/PostType.cs
Normal file
16
North_Bridge/North_Bridge_Contract/Enums/PostType.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace North_Bridge_Contract.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Supervisor = 1,
|
||||
Cashier = 2,
|
||||
Loader = 3,
|
||||
Consultant = 4
|
||||
}
|
17
North_Bridge/North_Bridge_Contract/Enums/ProductType.cs
Normal file
17
North_Bridge/North_Bridge_Contract/Enums/ProductType.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace North_Bridge_Contract.Enums;
|
||||
|
||||
[Flags]
|
||||
public enum ProductType
|
||||
{
|
||||
None = 0,
|
||||
SystemUnit = 1,
|
||||
Monitor = 2,
|
||||
ComputerMouse = 4,
|
||||
AudioSystem = 8
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace North_Bridge_Contract.Exceptions;
|
||||
|
||||
public class ValidationException : Exception
|
||||
{
|
||||
public ValidationException(string message) : base(message)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace North_Bridge_Contract.Extentions;
|
||||
|
||||
public static class StringExtentions
|
||||
{
|
||||
|
||||
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,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace North_Bridge_Contract.Infrastructure;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user