Добавьте файлы проекта.

This commit is contained in:
zcher
2025-12-14 18:05:36 +03:00
committed by yato
parent 64b6e01512
commit 84abc28e16
7 changed files with 228 additions and 0 deletions

61
User.cs Normal file
View File

@@ -0,0 +1,61 @@
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;
}
}
}