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