-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.cs
More file actions
123 lines (101 loc) · 3.06 KB
/
Book.cs
File metadata and controls
123 lines (101 loc) · 3.06 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace LibraryAppInteractive.BusinessLogic
{
public class Book
{
#region Fields
protected string _bookName;
protected string _bookISBN;
protected List<string> _bookAuthorList;
protected List<LibraryAsset> _libAssetList;
protected int _nCopies;
#endregion
#region Constructors
public Book(string bookName, string bookISBN)
{
_bookName = bookName;
_bookISBN = bookISBN;
_bookAuthorList = new List<string>();
_libAssetList = new List<LibraryAsset>();
}
#endregion
#region Properties
public string Name
{
get { return _bookName; }
set { _bookName = value; }
}
public string ISBN
{
get { return _bookISBN; }
set { _bookISBN = value; }
}
public List<string> Authors
{
get { return _bookAuthorList; }
set { _bookAuthorList= value; }
}
public IEnumerable<LibraryAsset> Assets
{
get { return _libAssetList; }
}
public int Copies
{
get { return _nCopies; }
set { _nCopies = value; }
}
#endregion
#region Methods
public (bool, LibraryAsset) CheckAvailability()
{
LibraryAsset asset = _libAssetList.FirstOrDefault(iAsset => iAsset.IsAvailable);
return(asset != null, asset);
}
public virtual LibraryAsset BorrowBook()
{
LibraryAsset asset = _libAssetList.FirstOrDefault(iAsset => iAsset.IsAvailable);
if (asset != null)
{
asset.Status = AssetStatus.Loaned;
return asset;
}
return null;
}
public virtual (TimeSpan, int, decimal) ReturnBook(int libID)
{
LibraryAsset asset = _libAssetList.FirstOrDefault(iAsset => iAsset.LibraryID == libID);
if(asset != null)
{
asset.Status = AssetStatus.Available;
return (TimeSpan.Zero, 0, 0m);
}
return (TimeSpan.Zero, 0, 0m);
}
public LibraryAsset ReserveBook()
{
LibraryAsset asset = _libAssetList.FirstOrDefault(iAsset => iAsset.Status == AssetStatus.Available);
if (asset != null)
{
asset.Status = AssetStatus.Reserved;
return asset;
}
return null;
}
public void AddAsset(LibraryAsset asset)
{
_libAssetList.Add(asset);
}
private LibraryAsset FindLibraryAsset(int libID)
{
return _libAssetList.FirstOrDefault(iAsset => iAsset.LibraryID==libID);
}
private LibraryAsset FindNextAvailableAsset()
{
return _libAssetList.FirstOrDefault(iAsset => iAsset.IsAvailable);
}
#endregion
}
}