35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System;
|
||
using System.Text.RegularExpressions;
|
||
using CandyHouseBase.Enums;
|
||
using CandyHouseBase.Exceptions;
|
||
using CandyHouseBase.Extensions;
|
||
using CandyHouseBase.Infrastructure;
|
||
|
||
namespace CandyHouseBase.DataModels
|
||
{
|
||
public class PositionDataModel : IValidation
|
||
{
|
||
public string Id { get; set; }
|
||
public PositionType Type { get; set; }
|
||
public string Title { get; set; }
|
||
|
||
public PositionDataModel(string id, PositionType type, string title)
|
||
{
|
||
Id = id;
|
||
Type = type;
|
||
Title = title;
|
||
}
|
||
|
||
public void Validate()
|
||
{
|
||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||
var titlePattern = @"^[A-Za-zА-Яа-яЁё\s\-]+$";
|
||
if (!Regex.IsMatch(Title, titlePattern))
|
||
throw new ValidationException("FIO contains invalid characters");
|
||
|
||
if (string.IsNullOrEmpty(Title)) throw new ValidationException("Field Title is empty");
|
||
if (!Enum.IsDefined(typeof(PositionType), Type)) throw new ValidationException("Invalid PositionType");
|
||
}
|
||
}
|
||
} |