-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathRegistration.cs
More file actions
52 lines (41 loc) · 1.21 KB
/
Registration.cs
File metadata and controls
52 lines (41 loc) · 1.21 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
using System;
using System.Collections.Generic;
using System.Linq;
namespace Exercise
{
public interface IRegistrable
{
RegisteredObject GetRegistrationInfo();
}
public static class RegistrationRepository
{
private static readonly List<RegisteredObject> RegisteredList = new List<RegisteredObject>();
private static int _nextId = 1;
public static int Register(IRegistrable registrable)
{
var info = registrable.GetRegistrationInfo();
if (info == null) return -1;
info.Id = _nextId;
RegisteredList.Add(info);
_nextId = RegisteredList.Count + 1;
return info.Id;
}
public static int DeleteAllRegisteredItems()
{
var size = RegisteredList.Count();
RegisteredList.RemoveRange(0, size);
_nextId = 1;
return size;
}
}
public class RegisteredObject
{
public string Info { get; set; }
public int Id { get; set; }
public int AvailableAmount { get; set; }
public override string ToString()
{
return Info + " " + "Available: " + AvailableAmount;
}
}
}