diff --git a/PimpMyRideProject/PimpMyRideContracts/DataModels/CarDataModel.cs b/PimpMyRideProject/PimpMyRideContracts/DataModels/CarDataModel.cs new file mode 100644 index 0000000..6ffb133 --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/DataModels/CarDataModel.cs @@ -0,0 +1,35 @@ +using System.Text.RegularExpressions; +using PimpMyRideContracts.Exceptions; +using PimpMyRideContracts.Extensions; +using PimpMyRideContracts.Infrastructure; + +namespace PimpMyRideContracts.DataModels; + +public class CarDataModel(string carId, string carMark, string carModel, string carNumber) : IValidation +{ + public string CarId { get; private set; } = carId; + public string CarMark { get; private set; } = carMark; + public string CarModel { get; private set; } = carModel; + public string CarNumber { get; private set; } = carNumber; + + public void Validate() + { + if (CarId.IsEmpty()) + throw new ValidationException("Field CarId is empty"); + + if (!CarId.IsGuid()) + throw new ValidationException("The value in the field CarId is not a unique identifier"); + + if (CarMark.IsEmpty()) + throw new ValidationException("Field CarMark is empty"); + + if (CarModel.IsEmpty()) + throw new ValidationException("Field CarModel is empty"); + + if (CarNumber.IsEmpty()) + throw new ValidationException("Field CarNumber is empty"); + + if (!Regex.IsMatch(CarNumber, @"^[АВЕКМНОРСТУХ]\d{3}(? supplies) : IValidation +{ + public string OperationId { get; private set; } = operationId; + public OperationType OperationType { get; private set; } = operationType; + public List Supplies { get; private set; } = supplies; + + public void Validate() + { + if (OperationId.IsEmpty()) + throw new ValidationException("Field OperationId is empty"); + + if (!OperationId.IsGuid()) + throw new ValidationException("The value in the field OperationId is not a unique identifier"); + + if ((Supplies?.Count ?? 0) == 0) + throw new ValidationException("The operation must include supplies"); + } +} diff --git a/PimpMyRideProject/PimpMyRideContracts/DataModels/OperationSupplieDataModel.cs b/PimpMyRideProject/PimpMyRideContracts/DataModels/OperationSupplieDataModel.cs new file mode 100644 index 0000000..bf3e0a4 --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/DataModels/OperationSupplieDataModel.cs @@ -0,0 +1,30 @@ +using PimpMyRideContracts.Exceptions; +using PimpMyRideContracts.Extensions; +using PimpMyRideContracts.Infrastructure; + +namespace PimpMyRideContracts.DataModels; + +public class OperationSupplieDataModel(string operationId, string supplieId, int supplieCount) : IValidation +{ + public string OperationId { get; private set; } = operationId; + public string SupplieId { get; private set; } = supplieId; + public int SupplieCount { get; private set; } = supplieCount; + + public void Validate() + { + if (OperationId.IsEmpty()) + throw new ValidationException("Field OperationId is empty"); + + if (!OperationId.IsGuid()) + throw new ValidationException("The value in the field OperationId is not a unique identifier"); + + if (SupplieId.IsEmpty()) + throw new ValidationException("Field SupplieId is empty"); + + if (!SupplieId.IsGuid()) + throw new ValidationException("The value in the field SupplieId is not a unique identifier"); + + if (SupplieCount <= 0) + throw new ValidationException("The value in field SupplieCount less ot equal 0"); + } +} diff --git a/PimpMyRideProject/PimpMyRideContracts/DataModels/ServiceDataModel.cs b/PimpMyRideProject/PimpMyRideContracts/DataModels/ServiceDataModel.cs new file mode 100644 index 0000000..d50939f --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/DataModels/ServiceDataModel.cs @@ -0,0 +1,37 @@ +using PimpMyRideContracts.Exceptions; +using PimpMyRideContracts.Extensions; +using PimpMyRideContracts.Infrastructure; + +namespace PimpMyRideContracts.DataModels; + +public class ServiceDataModel(string serviceId, string workerId, string carId, List operations) : IValidation +{ + public string ServiceId { get; private set; } = serviceId; + public string WorkerId { get; private set; } = workerId; + public string CarId { get; private set; } = carId; + public List Operations { get; private set; } = operations; + + public void Validate() + { + if (ServiceId.IsEmpty()) + throw new ValidationException("Field ServiceId is empty"); + + if (!ServiceId.IsGuid()) + throw new ValidationException("The value in the field ServiceId 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 (CarId.IsEmpty()) + throw new ValidationException("Field CarId is empty"); + + if (!CarId.IsGuid()) + throw new ValidationException("The value in the field CarId is not a unique identifier"); + + if ((Operations?.Count ?? 0) == 0) + throw new ValidationException("The service must include operations"); + } +} diff --git a/PimpMyRideProject/PimpMyRideContracts/DataModels/ServiceOperationDataModel.cs b/PimpMyRideProject/PimpMyRideContracts/DataModels/ServiceOperationDataModel.cs new file mode 100644 index 0000000..8180ebc --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/DataModels/ServiceOperationDataModel.cs @@ -0,0 +1,26 @@ +using PimpMyRideContracts.Exceptions; +using PimpMyRideContracts.Extensions; +using PimpMyRideContracts.Infrastructure; + +namespace PimpMyRideContracts.DataModels; + +public class ServiceOperationDataModel(string serviceId, string operationId) : IValidation +{ + public string ServiceId { get; private set; } = serviceId; + public string OperationId { get; private set; } = operationId; + + public void Validate() + { + if(OperationId.IsEmpty()) + throw new ValidationException("Field OperationId is empty"); + + if (!OperationId.IsGuid()) + throw new ValidationException("The value in the field OperationId is not a unique identifier"); + + if(ServiceId.IsEmpty()) + throw new ValidationException("Field ServiceId is empty"); + + if (!ServiceId.IsGuid()) + throw new ValidationException("The value in the field ServiceId is not a unique identifier"); + } +} diff --git a/PimpMyRideProject/PimpMyRideContracts/DataModels/SuppliesDataModel.cs b/PimpMyRideProject/PimpMyRideContracts/DataModels/SuppliesDataModel.cs new file mode 100644 index 0000000..816f2df --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/DataModels/SuppliesDataModel.cs @@ -0,0 +1,28 @@ +using PimpMyRideContracts.Enums; +using PimpMyRideContracts.Exceptions; +using PimpMyRideContracts.Extensions; +using PimpMyRideContracts.Infrastructure; + +namespace PimpMyRideContracts.DataModels; + +public class SuppliesDataModel(string supplieId, string supplieName, SuppliesType supplieType) : IValidation +{ + public string SupplieId { get; private set; } = supplieId; + public string SupplieName { get; private set; } = supplieName; + public SuppliesType SupplieType { get; private set; } = supplieType; + + public void Validate() + { + if (SupplieId.IsEmpty()) + throw new ValidationException("Field SupplieId is empty"); + + if (!SupplieId.IsGuid()) + throw new ValidationException("The value in the field SupplieId is not a unique identifier"); + + if (SupplieName.IsEmpty()) + throw new ValidationException("Field SupplieName is empty"); + + if (SupplieType == SuppliesType.None) + throw new ValidationException("Field SupplieType is empty"); + } +} diff --git a/PimpMyRideProject/PimpMyRideContracts/DataModels/WorkerDataModel.cs b/PimpMyRideProject/PimpMyRideContracts/DataModels/WorkerDataModel.cs new file mode 100644 index 0000000..b9c1e7d --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/DataModels/WorkerDataModel.cs @@ -0,0 +1,28 @@ +using PimpMyRideContracts.Enums; +using PimpMyRideContracts.Exceptions; +using PimpMyRideContracts.Extensions; +using PimpMyRideContracts.Infrastructure; + +namespace PimpMyRideContracts.DataModels; + +public class WorkerDataModel(string workerId, string workerFIO, PostType postType) : IValidation +{ + public string WorkerId { get; private set; } = workerId; + public string WorkerFIO { get; private set; } = workerFIO; + public PostType PostType { get; private set; } = postType; + + 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 (WorkerFIO.IsEmpty()) + throw new ValidationException("Field WorkerFIO is empty"); + + if (PostType == PostType.None) + throw new ValidationException("Field PostType is empty"); + } +} diff --git a/PimpMyRideProject/PimpMyRideContracts/Enums/OperationType.cs b/PimpMyRideProject/PimpMyRideContracts/Enums/OperationType.cs new file mode 100644 index 0000000..0190837 --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/Enums/OperationType.cs @@ -0,0 +1,11 @@ +namespace PimpMyRideContracts.Enums; + +public enum OperationType +{ + None = 0, + TireReplacement = 1, + PistonReplacement = 2, + TimingBeltReplacing = 3, + OilChange = 4, + BodyPainting = 5 +} diff --git a/PimpMyRideProject/PimpMyRideContracts/Enums/PostType.cs b/PimpMyRideProject/PimpMyRideContracts/Enums/PostType.cs new file mode 100644 index 0000000..19dd68b --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/Enums/PostType.cs @@ -0,0 +1,13 @@ +namespace PimpMyRideContracts.Enums; + +public enum PostType +{ + None = 0, + CarMechanic = 1, + CarElectrician = 2, + Straightener = 3, + BodyRepairSpecialist = 4, + TireFitter = 5, + CarDiagnosticTechnician = 6, + CarAirConditioningSpecialist = 7 +} diff --git a/PimpMyRideProject/PimpMyRideContracts/Enums/SuppliesType.cs b/PimpMyRideProject/PimpMyRideContracts/Enums/SuppliesType.cs new file mode 100644 index 0000000..fe53cdb --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/Enums/SuppliesType.cs @@ -0,0 +1,13 @@ +namespace PimpMyRideContracts.Enums; + +public enum SuppliesType +{ + None = 0, + Suspension = 1, + Engine = 2, + Gearbox = 3, + Tires = 4, + Rims = 5, + Electronics = 6, + Body = 7 +} diff --git a/PimpMyRideProject/PimpMyRideContracts/Exceptions/ValidationException.cs b/PimpMyRideProject/PimpMyRideContracts/Exceptions/ValidationException.cs new file mode 100644 index 0000000..d3dc13c --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/Exceptions/ValidationException.cs @@ -0,0 +1,5 @@ +namespace PimpMyRideContracts.Exceptions; + +public class ValidationException(string message) : Exception(message) +{ +} diff --git a/PimpMyRideProject/PimpMyRideContracts/Extensions/StringExtensions.cs b/PimpMyRideProject/PimpMyRideContracts/Extensions/StringExtensions.cs new file mode 100644 index 0000000..9e24840 --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/Extensions/StringExtensions.cs @@ -0,0 +1,14 @@ +namespace PimpMyRideContracts.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 _); + } +} diff --git a/PimpMyRideProject/PimpMyRideContracts/Infrastructure/IValidation.cs b/PimpMyRideProject/PimpMyRideContracts/Infrastructure/IValidation.cs new file mode 100644 index 0000000..4c17c6b --- /dev/null +++ b/PimpMyRideProject/PimpMyRideContracts/Infrastructure/IValidation.cs @@ -0,0 +1,6 @@ +namespace PimpMyRideContracts.Infrastructure; + +public interface IValidation +{ + void Validate(); +}