-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathRegistration.cs
More file actions
59 lines (48 loc) · 1.56 KB
/
Registration.cs
File metadata and controls
59 lines (48 loc) · 1.56 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
using System;
using System.Collections.Generic;
using System.Linq;
namespace Exercise
{
public interface IRegistrable
{
RegisteredObject GetRegistrationInfo();
}
public static class RegistrationRepository
{
//registered objects list
private static List<RegisteredObject> _registeredList = new List<RegisteredObject>();
private static int _nextId = 1;
//With BRIDGE pattern, implement Register method so it will accept both a Person and an Item
public static int Register(IRegistrable registarable)
{
//get info from an lib object
var info = registarable.GetRegistrationInfo();
if (info == null) return -1;
//get new id for for the registered object
info.Id = _nextId;
//add to registration repository
_registeredList.Add(info);
//store next available id
_nextId = _registeredList.Count + 1;
//return success
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 string.Format("{0} Available: {1}", Info, AvailableAmount);
}
}
}