42 lines
1.9 KiB
C#
42 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ClassLibrary1
|
|
{
|
|
public class Author(string id, string fio, string email, DateTime birthDate, string work, string articleId) : IValidation
|
|
{
|
|
public string Id { get; set; } = id;
|
|
public string FIO { get; set; } = fio;
|
|
public string Email { get; set; } = email;
|
|
public DateTime BirthDate { get; private set; } = birthDate;
|
|
public string Work { get; set; } = work;
|
|
public string ArticleId { get; set; } = articleId;
|
|
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 (FIO.IsEmpty())
|
|
throw new ValidationException("Field FIO is empty");
|
|
if (ArticleId.IsEmpty())
|
|
throw new ValidationException("Field ArticleId is empty");
|
|
if (!ArticleId.IsGuid())
|
|
throw new ValidationException("The value in the field ArticleId is not a unique identifier");
|
|
if (Work.IsEmpty())
|
|
throw new ValidationException("Field ArticleId is empty");
|
|
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
|
|
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
|
if (Email.IsEmpty())
|
|
throw new ValidationException("Field Email is empty");
|
|
if (!Regex.IsMatch(Email, @"^([a-zA-Z0-9._%-]+)@([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,})$"))
|
|
throw new ValidationException("Field Email is not a valid email address");
|
|
}
|
|
}
|
|
}
|