Добавьте файлы проекта.
This commit is contained in:
61
User.cs
Normal file
61
User.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user