34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
|
using System.Text.RegularExpressions;
|
|||
|
using TwoFromTheCaseContracts.Exceptions;
|
|||
|
using TwoFromTheCaseContracts.Extensions;
|
|||
|
using TwoFromTheCaseContracts.Infrastructure;
|
|||
|
|
|||
|
namespace TwoFromTheCaseContracts.DataModels;
|
|||
|
|
|||
|
public class CustomerDataModel(string id, string name, string phoneNumber) : IValidation
|
|||
|
{
|
|||
|
public string Id { get; private set; } = id;
|
|||
|
|
|||
|
public string Name { get; private set; } = name;
|
|||
|
|
|||
|
public string PhoneNumber { get; private set; } = phoneNumber;
|
|||
|
|
|||
|
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 (Name.IsEmpty())
|
|||
|
throw new ValidationException("Field Name is empty");
|
|||
|
|
|||
|
if (PhoneNumber.IsEmpty())
|
|||
|
throw new ValidationException("Field PhoneNumber is empty");
|
|||
|
|
|||
|
if (!Regex.IsMatch(PhoneNumber, @"^((\+7|7|8)+([0-9]){10})$"))
|
|||
|
throw new ValidationException("Field PhoneNumber is not a phone number");
|
|||
|
}
|
|||
|
}
|