42 lines
1.6 KiB
C#
Raw Permalink Normal View History

2025-02-25 15:42:57 +04:00
using System.Collections.Generic;
using System.Text.RegularExpressions;
2025-02-12 22:16:56 +04:00
using CandyHouseBase.Exceptions;
using CandyHouseBase.Infrastructure;
using CandyHouseBase.Extensions;
namespace CandyHouseBase.DataModels
{
public class PekarDataModel : IValidation
{
public string Id { get; private set; }
public string FIO { get; private set; }
public string Position { get; private set; }
public decimal BonusCoefficient { get; private set; }
2025-02-25 15:42:57 +04:00
public List<ProductDataModel> ProductsItems { get; private set; }
2025-02-12 22:16:56 +04:00
2025-02-25 15:42:57 +04:00
public PekarDataModel(string id, string fio, string position, decimal bonusCoefficient,
List<ProductDataModel> productsItems)
2025-02-12 22:16:56 +04:00
{
Id = id;
FIO = fio;
Position = position;
BonusCoefficient = bonusCoefficient;
2025-02-25 15:42:57 +04:00
ProductsItems = productsItems;
2025-02-12 22:16:56 +04:00
}
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");
2025-02-25 15:42:57 +04:00
var fioPattern = @"^[A-Za-zА-Яа-яЁё\s\-]+$";
if (!Regex.IsMatch(FIO, fioPattern))
throw new ValidationException("FIO contains invalid characters");
2025-02-12 22:16:56 +04:00
if (Position.IsEmpty()) throw new ValidationException("Field Position is empty");
2025-02-13 16:13:21 +04:00
if (!Position.IsGuid()) throw new ValidationException("Field must be a GUID");
2025-02-12 22:16:56 +04:00
if (BonusCoefficient <= 0) throw new ValidationException("BonusCoefficient must be positive");
}
}
}