This commit is contained in:
2025-02-12 18:46:47 +04:00
parent 4711b3fada
commit 8150c8c96b
13 changed files with 330 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
using SmallSoftwareContracts.Exceptions;
using SmallSoftwareContracts.Extensions;
using SmallSoftwareContracts.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SmallSoftwareContracts.DataModels;
public class InstallationRequestDataModel(string softwareId, string requestId, int count) : IValidation
{
public string SoftwareId { get; private set; } = softwareId;
public string RequestId { get; private set; } = requestId;
public int Count { get; private set; } = count;
public void Validate()
{
if (SoftwareId.IsEmpty())
throw new ValidationException("Field SoftwareId is empty");
if (!SoftwareId.IsGuid())
throw new ValidationException("The value in the field SoftwareId is not a unique identifier");
if (RequestId.IsEmpty())
throw new ValidationException("Field RequestId is empty");
if (!RequestId.IsGuid())
throw new ValidationException("The value in the field RequestId is not a unique identifier");
if (Count <= 0)
throw new ValidationException("Field Count is less than or equal to 0");
}
}

View File

@@ -0,0 +1,33 @@
using SmallSoftwareContracts.Exceptions;
using SmallSoftwareContracts.Extensions;
using SmallSoftwareContracts.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace SmallSoftwareContracts.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 is empty");
}
}

View File

@@ -0,0 +1,41 @@
using SmallSoftwareContracts.Enums;
using SmallSoftwareContracts.Exceptions;
using SmallSoftwareContracts.Extensions;
using SmallSoftwareContracts.Infrastructure;
namespace SmallSoftwareContracts.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;
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 PostType is empty");
if (Salary <= 0)
throw new ValidationException("Field Salary is empty");
}
}

View File

@@ -0,0 +1,38 @@
using SmallSoftwareContracts.Exceptions;
using SmallSoftwareContracts.Extensions;
using SmallSoftwareContracts.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace SmallSoftwareContracts.DataModels;
public class RequestDataModel(string id, string workerId, double sum,
bool isCancel, List<InstallationRequestDataModel> softwares) : IValidation
{
public string Id { get; private set; } = id;
public string WorkerId { get; private set; } = workerId;
public DateTime RequestDate { get; private set; } = DateTime.UtcNow;
public double Sum { get; private set; } = sum;
public bool IsCancel { get; private set; } = isCancel;
public List<InstallationRequestDataModel> Softwares { get; private set; } = softwares;
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 ((Softwares?.Count ?? 0) == 0)
throw new ValidationException("The sale must include Softwares");
}
}

View File

@@ -0,0 +1,28 @@
using SmallSoftwareContracts.Exceptions;
using SmallSoftwareContracts.Extensions;
using SmallSoftwareContracts.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SmallSoftwareContracts.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");
}
}

View File

@@ -0,0 +1,39 @@
using SmallSoftwareContracts.Enums;
using SmallSoftwareContracts.Exceptions;
using SmallSoftwareContracts.Extensions;
using SmallSoftwareContracts.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace SmallSoftwareContracts.DataModels;
public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, string manufacturerId, double price, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string SoftwareName { get; private set; } = softwareName;
public SoftwareType SoftwareType { get; private set; } = softwareType;
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 (SoftwareName.IsEmpty())
throw new ValidationException("Field SoftwareName is empty");
if (SoftwareType == SoftwareType.None)
throw new ValidationException("Field SoftwareType 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");
}
}

View File

@@ -0,0 +1,27 @@
using SmallSoftwareContracts.Exceptions;
using SmallSoftwareContracts.Extensions;
using SmallSoftwareContracts.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SmallSoftwareContracts.DataModels;
public class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IValidation
{
public string SoftwareId { get; private set; } = softwareId;
public double OldPrice { get; private set; } = oldPrice;
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
public void Validate()
{
if (SoftwareId.IsEmpty())
throw new ValidationException("Field SoftwareId is empty");
if (!SoftwareId.IsGuid())
throw new ValidationException("The value in the field SoftwareId is not a unique identifier");
if (OldPrice <= 0)
throw new ValidationException("Field OldPrice is less than or equal to 0");
}
}

View File

@@ -0,0 +1,36 @@
using SmallSoftwareContracts.Exceptions;
using SmallSoftwareContracts.Extensions;
using SmallSoftwareContracts.Infrastructure;
namespace SmallSoftwareContracts.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 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()})");
}
}

View File

@@ -0,0 +1,10 @@
namespace SmallSoftwareContracts.Enums;
public enum PostType
{
None = 0,
Supervisor = 1,
CashierConsultant = 2,
SoftInstaller = 3
}

View File

@@ -0,0 +1,11 @@
namespace SmallSoftwareContracts.Enums;
public enum SoftwareType
{
None = 0,
Windows = 1,
Linux = 2,
MacOS = 3,
AudioDriver = 4,
GPUDriver = 5
}

View File

@@ -0,0 +1,5 @@
namespace SmallSoftwareContracts.Exceptions;
public class ValidationException(string message) : Exception(message)
{
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SmallSoftwareContracts.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 _);
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SmallSoftwareContracts.Infrastructure;
public interface IValidation
{
void Validate();
}