61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using Microsoft.Win32;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Mail;
|
|
using System.Text;
|
|
|
|
namespace First_week
|
|
{
|
|
public 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}");
|
|
}
|
|
}
|
|
}
|
|
}
|