PIbd-22. Tukhtarov I.N. First lab #1
@ -20,17 +20,17 @@ public class ClientDataModel(string id, string fio, string phoneNumber) : IValid
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (id.isEmpty())
|
||||
if (Id.isEmpty())
|
||||
throw new ValidationFieldException("Field Id is empty");
|
||||
|
||||
if (!id.isGuid())
|
||||
if (!Id.isGuid())
|
||||
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (FIO.isEmpty())
|
||||
throw new ValidationFieldException("Field FIO is empty");
|
||||
|
||||
if (!Regex.IsMatch(FIO, @"^[A-ZА-ЯЁ][a-zа-яё]+ [A-ZА-ЯЁ][a-zа-яё]+ [A-ZA-ЯЁ][a-zа-яё]+$"))
|
||||
throw new ValidationFieldException("Field FIO is not a fio");
|
||||
if (!Regex.IsMatch(FIO, @"^[A-ZА-ЯЁ][a-zа-яё]+(?:-[A-ZА-ЯЁ][a-zа-яё]+)?\s[A-ZА-ЯЁ][a-zа-яё]+(?:-[A-ZА-ЯЁ][a-zа-яё]+)?\s[A-ZА-ЯЁ][a-zа-яё]+(?:-[A-ZА-ЯЁ][a-zа-яё]+)?$"))
|
||||
throw new ValidationFieldException("Field FIO is not a valid full name.");
|
||||
|
||||
if (PhoneNumber.isEmpty())
|
||||
throw new ValidationFieldException("Field PhoneNumber is empty");
|
||||
|
@ -11,12 +11,17 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class CompanyDataModel(string id, string companyName, string prevCompanyName, string prevPrevCompanyName) : IValidation
|
||||
public class CompanyDataModel(string id, string companyName, string prevCompanyName,
|
||||
string prevPrevCompanyName) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string CompanyName { get; private set; } = companyName;
|
||||
|
||||
public string? PrevCompanyName { get; private set; } = prevCompanyName;
|
||||
|
||||
public string? PrevPrevCompanyName { get; private set; } = prevPrevCompanyName;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.isEmpty())
|
||||
|
@ -10,7 +10,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class InstallationDataModel(string id, string workerId, string clientId, double sum, bool isCancel, List<InstallationSoftwareDataModel> programs) : IValidation
|
||||
public class InstallationDataModel(string id, string workerId, string clientId,
|
||||
double sum, bool isCancel, List<InstallationSoftwareDataModel> programs) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
@ -18,7 +19,7 @@ public class InstallationDataModel(string id, string workerId, string clientId,
|
||||
|
||||
public string? ClientId { get; private set; } = clientId;
|
||||
|
||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||
public DateTime InstallationDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public double Sum { get; private set; } = sum;
|
||||
|
||||
|
@ -9,11 +9,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class InstallationSoftwareDataModel(string saleId, string programId, int count) : IValidation
|
||||
public class InstallationSoftwareDataModel(string installationId, string programId, int count) : IValidation
|
||||
{
|
||||
public string ProgramId { get; private set; } = programId;
|
||||
|
||||
public string SaleId { get; private set; } = saleId;
|
||||
public string InstallationId { get; private set; } = installationId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
@ -25,11 +25,11 @@ public class InstallationSoftwareDataModel(string saleId, string programId, int
|
||||
if (!ProgramId.isGuid())
|
||||
throw new ValidationFieldException("The value in the field ProgramId is not a unique identifier");
|
||||
|
||||
if (SaleId.isEmpty())
|
||||
throw new ValidationFieldException("Field SaleId is empty");
|
||||
if (InstallationId.isEmpty())
|
||||
throw new ValidationFieldException("Field InstallationId is empty");
|
||||
|
||||
if (!SaleId.isGuid())
|
||||
throw new ValidationFieldException("The value in the field SaleId is not a unique identifier");
|
||||
if (!InstallationId.isGuid())
|
||||
throw new ValidationFieldException("The value in the field InstallationId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationFieldException("Field Count is less than or equal to 0");
|
||||
|
@ -10,7 +10,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
||||
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;
|
||||
|
@ -10,7 +10,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, string companyId, double price, bool isDeleted) : IValidation
|
||||
public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType,
|
||||
string companyId, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
@ -33,10 +34,10 @@ public class SoftwareDataModel(string id, string softwareName, SoftwareType soft
|
||||
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (SoftwareName.isEmpty())
|
||||
throw new ValidationFieldException("Field ProgramName is empty");
|
||||
throw new ValidationFieldException("Field SoftwareName is empty");
|
||||
|
||||
if (SoftwareType == SoftwareType.None)
|
||||
throw new ValidationFieldException("Field ProgramType is empty");
|
||||
throw new ValidationFieldException("Field SoftwareType is empty");
|
||||
|
||||
if (CompanyId.isEmpty())
|
||||
throw new ValidationFieldException("Field CompanyId is empty");
|
||||
|
@ -21,10 +21,10 @@ public class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IVal
|
||||
public void Validate()
|
||||
{
|
||||
if (SoftwareId.isEmpty())
|
||||
throw new ValidationFieldException("Field ProgramId is empty");
|
||||
throw new ValidationFieldException("Field SoftwareId is empty");
|
||||
|
||||
if (!SoftwareId.isGuid())
|
||||
throw new ValidationFieldException("The value in the field ProgramId is not a unique identifier");
|
||||
throw new ValidationFieldException("The value in the field SoftwareId is not a unique identifier");
|
||||
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationFieldException("Field OldPrice is less than or equal to 0");
|
||||
|
@ -10,13 +10,19 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
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()
|
||||
@ -43,6 +49,8 @@ public class WorkerDataModel(string id, string fio, string postId, DateTime birt
|
||||
throw new ValidationFieldException("The date of employment cannot be less than the date of birth");
|
||||
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||
throw new ValidationFieldException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()}");
|
||||
throw new ValidationFieldException($"Minors cannot be hired " +
|
||||
$"(EmploymentDate - {EmploymentDate.ToShortDateString()}," +
|
||||
$" BirthDate - {BirthDate.ToShortDateString()}");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user