-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathRegistration.cs
More file actions
87 lines (68 loc) · 2.14 KB
/
Registration.cs
File metadata and controls
87 lines (68 loc) · 2.14 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
namespace Exercise
{
public interface IRegistarable
{
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(IRegistarable 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 Info + " " + "Available: " + AvailableAmount;
}
}
public interface IRegisterAPI
{
RegisteredObject GetRegisteredObject(LibObject libObject);
}
public class LibObjectRegisterAPI : IRegisterAPI
{
public LibObjectRegisterAPI()
{
}
public RegisteredObject GetRegisteredObject(LibObject libObject)
{
RegisteredObject regObJ = new RegisteredObject
{
Info = libObject.NameOrTitle,
AvailableAmount = libObject.AvailableAmount,
Id = libObject.ObjectId
};
return regObJ;
}
}
}