36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
|
using System.Text.RegularExpressions;
|
||
|
using CandyHouseBase.Exceptions;
|
||
|
using CandyHouseBase.Extensions;
|
||
|
using CandyHouseBase.Infrastructure;
|
||
|
|
||
|
namespace CandyHouseBase.DataModels
|
||
|
{
|
||
|
public class CustomerDataModel : IValidation
|
||
|
{
|
||
|
public string Id { get; private set; }
|
||
|
public string FIO { get; private set; }
|
||
|
public string Phone { get; private set; }
|
||
|
public string Email { get; private set; }
|
||
|
|
||
|
public CustomerDataModel(string id, string fio, string phone, string email)
|
||
|
{
|
||
|
Id = id;
|
||
|
FIO = fio;
|
||
|
Phone = phone;
|
||
|
Email = email;
|
||
|
}
|
||
|
|
||
|
public void Validate()
|
||
|
{
|
||
|
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||
|
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||
|
if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty");
|
||
|
if (Phone.IsEmpty()) throw new ValidationException("Field Phone is empty");
|
||
|
|
||
|
var phoneRegex = new Regex(@"^\+7\d{10}$");
|
||
|
if (!phoneRegex.IsMatch(Phone)) throw new ValidationException("Invalid phone format");
|
||
|
|
||
|
if (Email.IsEmpty() || !Email.Contains("@")) throw new ValidationException("Invalid email format");
|
||
|
}
|
||
|
}
|
||
|
}
|