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

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

60
UserManager.cs Normal file
View File

@@ -0,0 +1,60 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Net.Mail;
using System.Text;
namespace First_week
{
internal class UserManager
{
public List <User> Registory = new();
public void AddUser(User user)
{
CheckUniqe(user);
Registory.Add(user);
}
public void RemoveUser(Guid id)
{
User? user = Registory.Find(x => x.Id == id);
if (user == null)
return;
Registory.Remove(user);
}
public User Find(Guid id)
{
User? user = Registory.Find(x => x.Id == id);
if (user == null)
throw new Exception("Not found");
return user;
}
public User Find(MailAddress email)
{
User? user = Registory.Find(x => x.Email == email);
if (user == null)
throw new Exception("Not found");
return user;
}
private void CheckUniqe(User user)
{
if (Registory.FirstOrDefault(x => x.Equals(user)) != null)
throw new Exception("Such a user already exists");
}
public void Show()
{
foreach (var user in Registory)
{
Console.WriteLine($"{user.GetFullName} {user.Id}");
}
}
}
}