48 lines
1.5 KiB
C#
Raw Normal View History

2025-02-26 14:36:59 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WingsOfTheWorldContratcs.Exceptions;
using WingsOfTheWorldContratcs.Exstensions;
using WingsOfTheWorldContratcs.Infrastructure;
namespace WingsOfTheWorldContratcs.DataModels;
public class СarrierСompanyDataModel(string id, string name, string phoneNumber, int count, int price) : IValidation
{
public string Id { get; private set; } = id;
public string Name { get; private set; } = name;
public string PhoneNumber { get; private set; } = phoneNumber;
public int Count { get; private set; } = count;
public int Price { get; private set; } = price;
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, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
throw new ValidationException("Field PhoneNumber is not a phone number");
if (Count <= 0)
throw new ValidationException("Field Count is empty");
if (Price <= 0)
throw new ValidationException("Field Price is empty");
}
}