Files
UtilityLibrary/User.cs
2025-12-14 18:41:56 +03:00

62 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Net.Mail;
using System.Runtime.CompilerServices;
using System.Text;
namespace First_week
{
internal class User
{
public Guid Id { get; }
public string Name { get; private set; }
public string Surname { get; private set; }
public MailAddress? Email { get; private set; }
public DateOnly Date { get; private set; }
public bool IsActive { get; private set; }
public User(string name, string surname, MailAddress email, DateOnly date)
{
if (name == null || name.Length > 100)
throw new Exception("Incorrect name");
if (surname == null || surname.Length > 100)
throw new Exception("Incorrect surname");
if (date.CompareTo(DateOnly.FromDateTime(DateTime.Now)) > 0)
throw new Exception("Incorrect birthdate");
Id = Guid.NewGuid();
Name = name;
Surname = surname;
Email = email;
Date = date;
IsActive = true;
}
public string GetFullName()
{
return ($"{Surname} {Name}");
}
public void UpdateEmail(MailAddress newMail)
{
Email = newMail;
}
public void UpdateDate(DateOnly date)
{
if (date.CompareTo(DateOnly.FromDateTime(DateTime.Now)) > 0)
throw new Exception("Wrong date");
Date = date;
}
public void Deactivate()
{
IsActive = false;
}
}
}