-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientManager.cs
More file actions
62 lines (61 loc) · 1.76 KB
/
Copy pathClientManager.cs
File metadata and controls
62 lines (61 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace Lab1
{
internal class ClientManager
{
public List<Client> Clients { get; private set; }
public ClientManager()
{
Clients = new List<Client>();
LoadClients();
}
public void AddClient(Client client)
{
if (client == null)
{
throw new ArgumentNullException(nameof(client));
}
Clients.Add(client);
SaveClients();
}
public void RemoveClient(Client client)
{
if (client == null)
{
throw new ArgumentNullException(nameof(client));
}
Clients.Remove(client);
SaveClients();
}
public List<Client> SearchClients(string query)
{
return Clients.Where(c => c.Name.Contains(query) || c.Email.Contains(query) ||
c.Phone.Contains(query) || c.Address.Contains(query)).ToList();
}
private void SaveClients()
{
File.WriteAllLines("clients.txt", Clients.Select(c =>
$"{c.Name}|{c.Email}|{c.Phone}|{c.Address}"));
}
private void LoadClients()
{
if (File.Exists("clients.txt"))
{
var lines = File.ReadAllLines("clients.txt");
foreach (var line in lines)
{
var parts = line.Split('|');
if (parts.Length == 4)
{
Clients.Add(new Client(parts[0], parts[1], parts[2], parts[3]));
}
}
}
}
}
}