forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using MagicCarpetContracts.Extensions;
|
|
using MagicCarpetContracts.Exceptions;
|
|
using MagicCarpetContracts.Infrastructure;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using ValidationException = MagicCarpetContracts.Exceptions.ValidationException;
|
|
using MagicCarpetContracts.Resources;
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
namespace MagicCarpetContracts.DataModels;
|
|
|
|
internal class ClientDataModel(string id, string fIO, string phoneNumber, double discountSize) : IValidation
|
|
{
|
|
public string Id { get; private set; } = id;
|
|
|
|
public string FIO { get; private set; } = fIO;
|
|
|
|
public string PhoneNumber { get; private set; } = phoneNumber;
|
|
|
|
public double DiscountSize { get; private set; } = discountSize;
|
|
|
|
public ClientDataModel() : this(string.Empty, string.Empty, string.Empty, 0) { }
|
|
|
|
public void Validate(IStringLocalizer<Messages> localizer)
|
|
{
|
|
if (Id.IsEmpty())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
|
|
|
if (!Id.IsGuid())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
|
|
|
if (FIO.IsEmpty())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "FIO"));
|
|
|
|
if (PhoneNumber.IsEmpty())
|
|
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "PhoneNumber"));
|
|
|
|
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
|
throw new ValidationException(localizer["ValidationExceptionIncorrectPhoneNumber"]);
|
|
}
|
|
}
|