42 lines
1.6 KiB
C#
42 lines
1.6 KiB
C#
using System.Collections.Generic;
|
||
using System.Text.RegularExpressions;
|
||
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; }
|
||
public List<ProductDataModel> ProductsItems { get; private set; }
|
||
|
||
|
||
public PekarDataModel(string id, string fio, string position, decimal bonusCoefficient,
|
||
List<ProductDataModel> productsItems)
|
||
{
|
||
Id = id;
|
||
FIO = fio;
|
||
Position = position;
|
||
BonusCoefficient = bonusCoefficient;
|
||
ProductsItems = productsItems;
|
||
}
|
||
|
||
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");
|
||
var fioPattern = @"^[A-Za-zА-Яа-яЁё\s\-]+$";
|
||
if (!Regex.IsMatch(FIO, fioPattern))
|
||
throw new ValidationException("FIO contains invalid characters");
|
||
|
||
if (Position.IsEmpty()) throw new ValidationException("Field Position is empty");
|
||
if (!Position.IsGuid()) throw new ValidationException("Field must be a GUID");
|
||
if (BonusCoefficient <= 0) throw new ValidationException("BonusCoefficient must be positive");
|
||
}
|
||
}
|
||
} |