diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/Library.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/Library.cs
deleted file mode 100644
index 172f11d..0000000
--- a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/Library.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace LibraryAppInteractive;
-
-///
-/// Defines the Library class used to manage the library books and assets.
-///
-/// NOTE: A single object/instance of this class (called a "singleton") is created and shared automatically
-/// with the two pages in the application through the process of Dependency Injection handled and configured
-/// in MauiProgram class.
-///
-public class Library
-{
-}
\ No newline at end of file
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryAdminPage.xaml b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryAdminPage.xaml
index 416d3ce..e03c186 100644
--- a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryAdminPage.xaml
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryAdminPage.xaml
@@ -5,8 +5,13 @@
x:Class="LibraryAppInteractive.LibraryAdminPage"
Title="Manage Book Assets">
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryAdminPage.xaml.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryAdminPage.xaml.cs
index c9c0b9c..948cb8b 100644
--- a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryAdminPage.xaml.cs
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryAdminPage.xaml.cs
@@ -1,3 +1,4 @@
+using LibraryAppInteractive.businesslogic;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -8,8 +9,73 @@ namespace LibraryAppInteractive;
public partial class LibraryAdminPage : ContentPage
{
- public LibraryAdminPage()
+ private Library _library;
+ public LibraryAdminPage(Library library)
{
InitializeComponent();
+ _library = library;
+ }
+
+ private async void RegisterBook(object sender, EventArgs e)
+ {
+ //once the button is pressed it gets all the entries and then and then displays a alert telling you that it was registered if there was no problems
+ string name = _txtName.Text;
+ string isbn = _txtIsbn.Text;
+ string author = _txtAuthor.Text;
+ BookType type = BookType.Paper;
+ if (_txtType.Text == "Paper" || _txtType.Text == "paper")
+ {
+ type = BookType.Paper;
+ }
+ else if (_txtType.Text == "Digital" || _txtType.Text == "digital")
+ {
+ type = BookType.Digital;
+ }
+ else
+ {
+ await DisplayAlert("error","Needs to be either paper or digital","Ok");
+ }
+
+ if (string.IsNullOrWhiteSpace(name) ||
+ string.IsNullOrWhiteSpace(isbn))
+ {
+ await DisplayAlert("Error", "Name and ISBN required", "OK");
+ return;
+ }
+ //had to google how to split mutiple authors into a array
+ string[] authors = author?
+ .Split(',', StringSplitOptions.RemoveEmptyEntries)
+ .Select(a => a.Trim())
+ .ToArray() ?? new string[0];
+
+ int copies = 1;
+
+ _library.RegisterBook(
+ name,isbn,authors,type,copies
+
+ );
+ await DisplayAlert("Success", "Book registered", "OK");
+
+ }
+
+ private async void DisplayBooks(object sender, EventArgs e)
+ {
+ //shows the list of all the books in a displayalert
+ var books = _library.GetAllBooks();
+
+ if (books == null || books.Count == 0)
+ {
+ await DisplayAlert("Library", "No books available", "OK");
+ return;
+ }
+
+ string result = "";
+
+ foreach (var book in books)
+ {
+ result += $"{book.Name} ({book.ISBN})\n";
+ }
+
+ await DisplayAlert("Books", result, "OK");
}
}
\ No newline at end of file
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryApp.csproj b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryApp.csproj
index 2d4bcbc..d7fa65d 100644
--- a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryApp.csproj
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryApp.csproj
@@ -35,21 +35,21 @@
-
+
-
+
-
-
-
+
+
+
-
+
-
+
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryBrowsePage.xaml b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryBrowsePage.xaml
index 91c0947..b5573ec 100644
--- a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryBrowsePage.xaml
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryBrowsePage.xaml
@@ -3,8 +3,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LibraryAppInteractive.LibraryBrowsePage"
Title="Browse Interactive Library">
-
-
+
+
+
+
+
+
+
+
+
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryBrowsePage.xaml.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryBrowsePage.xaml.cs
index 2e8fc26..536177d 100644
--- a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryBrowsePage.xaml.cs
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/LibraryBrowsePage.xaml.cs
@@ -1,9 +1,88 @@
-namespace LibraryAppInteractive;
+using LibraryAppInteractive.businesslogic;
+
+namespace LibraryAppInteractive;
public partial class LibraryBrowsePage : ContentPage
{
- public LibraryBrowsePage()
+ public Library _library;
+ public LibraryBrowsePage(Library library)
{
InitializeComponent();
+ _library = library;
+ _library.CreateDefaultBooks();
+
+ }
+
+ private async void SearchBook(object sender, EventArgs e)
+ {
+ //lets you search for a book if it available and matches the name you type in case sensitive
+ if (_library == null)
+ {
+ await DisplayAlert("Error", "Library not initialized", "OK");
+ return;
+ }
+ string bookName = _txtbookname.Text;
+ Book book = _library.FindBookByName(bookName);
+
+ if (book == null)
+ {
+ await DisplayAlert("Not found","No book availble","Ok");
+ return;
+ }
+ await DisplayAlert("Book found",$"Found the book {bookName}","Ok");
+ }
+
+ private async void BorrowBook(object sender, EventArgs e)
+ {
+ //lets you borrow a book based on the isbm given and then displays a alert saying you got the book
+ if (_library == null)
+ {
+ await DisplayAlert("Error", "Library not initialized", "OK");
+ return;
+ }
+ string isbn = _txtISBN.Text?.Trim();
+ Book book = _library.FindBookByISBN(isbn);
+ if (book == null)
+ {
+ await DisplayAlert("Not found","No book found","Ok");
+ return;
+
+ }
+
+ LibraryAsset asset = book.BorrowBook();
+ if (asset == null)
+ {
+ await DisplayAlert("Not found", "No copies found", "Ok");
+ return;
+ }
+ await DisplayAlert("Book found", $"Borrowed the book {book.Name}", "Ok");
+
+ }
+
+ private async void OnReturnBook(object sender, EventArgs e)
+ {
+ //lets you return the book based off of the libid and isbn number and then adds it to the copy and then displays a alert saying its returned
+ if (_library == null)
+ {
+ await DisplayAlert("Error", "Library not initialized", "OK");
+ return;
+ }
+ string isbn = _txtISBN.Text;
+ if (!int.TryParse(_txtLibID.Text, out int libId))
+ {
+ await DisplayAlert("Error", "Please enter a valid numeric Library ID", "OK");
+ return;
+ }
+ int LibId = int.Parse(_txtLibID.Text);
+ Book book = _library.FindBookByISBN(isbn);
+ if (book == null)
+ {
+ await DisplayAlert("Not found", "No book found", "Ok");
+ return;
+ }
+
+ var result = book.ReturnBook(LibId);
+
+ await DisplayAlert("Book returned",$"Returned the book {book.Name}","Ok");
}
}
\ No newline at end of file
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/MauiProgram.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/MauiProgram.cs
index 9fe3540..f8cb079 100644
--- a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/MauiProgram.cs
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/MauiProgram.cs
@@ -1,4 +1,5 @@
-using System.Collections.Immutable;
+using LibraryAppInteractive.businesslogic;
+using System.Collections.Immutable;
namespace LibraryAppInteractive;
@@ -14,7 +15,10 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
-
+ builder.Services.AddSingleton();
+
+ builder.Services.AddTransient();
+ builder.Services.AddTransient();
return builder.Build();
}
}
\ No newline at end of file
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/Book.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/Book.cs
new file mode 100644
index 0000000..377ca67
--- /dev/null
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/Book.cs
@@ -0,0 +1,137 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LibraryAppInteractive.businesslogic;
+
+public class Book
+{
+ //sets all the variables
+ protected string _bookName;
+ protected string _bookISBN;
+ protected List _bookAuthorList;
+ protected List _libAssetList;
+
+ public string Name { get; set; }
+ public string ISBN { get; set; }
+ public List Authors { get; set; }
+ //gets the list of assets
+ public IEnumerable Assets
+ {
+ get
+ {
+ return _libAssetList;
+ }
+ }
+
+ public Book(string bookName, string bookISBN)
+ {
+ //gives the variables a value
+ Name = bookName;
+ ISBN = bookISBN;
+ _libAssetList = new List();
+ _bookAuthorList = new List();
+ }
+
+ public virtual bool CheckAvailability()
+ {
+ //checks the books availbility and wether its true or not
+ if (_libAssetList.Count == 0 || _libAssetList == null)
+ {
+ return false;
+ }
+ foreach (var asset in _libAssetList)
+ {
+ if (asset.Status == AssetStatus.Available)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public virtual LibraryAsset BorrowBook()
+ {
+ //lets you borrow a book if the book has the available status
+ foreach (var asset in _libAssetList)
+ {
+ if (asset.Status == AssetStatus.Available)
+ {
+ asset.Status = AssetStatus.Loaned;
+ //used google to find the information on the datetime command
+ asset.Loan = new LoanPeriod(DateTime.Now, DateTime.MinValue, 30);
+ return asset;
+ }
+ }
+
+ return null;
+ }
+
+ public virtual (TimeSpan, int, decimal) ReturnBook(int libID)
+ {
+ //lets you return the book and add it back to the copies
+ var asset = findLibraryAsset(libID);
+ if (asset == null)
+ {
+ return (TimeSpan.Zero, 0, 0);
+ }
+
+ if (asset.Status != AssetStatus.Loaned)
+ {
+ return (TimeSpan.Zero, 0, 0);
+ }
+
+ DateTime returnTime = DateTime.Now;
+ TimeSpan durationLoaned = returnTime - asset.Loan.BorrowedOn;
+
+ int daysLate = (returnTime - asset.Loan.BorrowedOn).Days - 30;
+ //googled how to make a decimal literal with m
+ if (daysLate < 0)
+ {
+ daysLate = 0;
+ }
+ decimal penaltyFee = daysLate * 0.5m;
+ asset.Status = AssetStatus.Available;
+ asset.Loan = new LoanPeriod(DateTime.MinValue, DateTime.MinValue, 30);
+ return (durationLoaned, daysLate,penaltyFee);
+ }
+
+ public LibraryAsset findLibraryAsset(int libID)
+ {
+ //gives you the library id
+ foreach (var asset in _libAssetList)
+ {
+ if (asset._libID == libID)
+ {
+ return asset;
+ }
+ }
+ return null;
+ }
+
+ public LibraryAsset findNextAvailableAsset()
+ {
+ //finds the next availble asset that is availble
+ if (_libAssetList == null)
+ {
+ return null;
+ }
+ foreach (var asset in _libAssetList)
+ {
+ if (asset.Status == AssetStatus.Available)
+ return asset;
+ }
+
+ return null;
+ }
+
+ public void AddAsset(LibraryAsset asset)
+ {
+ //adds the asset to the list of books
+ if (_libAssetList == null)
+ {
+ _libAssetList = new List();
+ }
+ _libAssetList.Add(asset);
+ }
+}
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/Library.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/Library.cs
new file mode 100644
index 0000000..a182eb1
--- /dev/null
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/Library.cs
@@ -0,0 +1,125 @@
+
+namespace LibraryAppInteractive.businesslogic;
+
+///
+/// Defines the Library class used to manage the library books and assets.
+///
+/// NOTE: A single object/instance of this class (called a "singleton") is created and shared automatically
+/// with the two pages in the application through the process of Dependency Injection handled and configured
+/// in MauiProgram class.
+///
+public class Library
+{
+ private List _bookList;
+ private int _libraryIdGeneratorSeed;
+ private const int default_libid_start = 100;
+
+ public Library()
+ {
+ //creates a list of the books and the id
+ _bookList = new List();
+ _libraryIdGeneratorSeed = 0;
+ }
+
+ public void CreateDefaultBooks()
+ {
+ //a default set of books
+ RegisterBook(
+ "Book1",
+ "1234",
+ new string[] {"ME"},
+ BookType.Paper,
+ 4
+ );
+ RegisterBook(
+ "Book2",
+ "4567",
+ new string[] { "ME","MYSELF","I" },
+ BookType.Digital,
+ 1
+ );
+ RegisterBook(
+ "Book3",
+ "8976",
+ new string[] { "ME","YOU" },
+ BookType.Paper,
+ 2
+ );
+ }
+
+ public int DetermineLibId()
+ {
+ //adds one to the id
+ return _libraryIdGeneratorSeed++;
+ }
+
+ public Book RegisterBook(string bookName, string bookISBN, string[] authors, BookType bookType, int nCopies)
+ {
+ //registers a book to the list and all the info given as a book object
+ Book newbook;
+ switch (bookType)
+ {
+ case BookType.Paper:
+ newbook = new PaperBook(bookName, bookISBN);
+ break;
+
+ case BookType.Digital:
+ newbook = new DigitalBook(bookName, bookISBN);
+ break;
+
+ default:
+ throw new Exception("not a valid book");
+ }
+ newbook.Authors = authors.ToList();
+
+ for (int i = 0; i < nCopies; i++)
+ {
+ int id = DetermineLibId();
+ LibraryAsset asset = new LibraryAsset(id, newbook);
+
+ newbook.AddAsset(asset);
+ }
+ _bookList.Add(newbook);
+
+ return newbook;
+ }
+
+ public Book FindBookByName(string bookName)
+ {
+ //lets you find the book by its name by iterating through the list of books until it matches
+ if (_bookList == null)
+ {
+ return null;
+ }
+ foreach (Book book in _bookList)
+ {
+ if (book.Name != null && book.Name.Equals(bookName))
+ {
+ return book;
+ }
+ }
+ return null;
+ }
+
+ public Book FindBookByISBN(string bookISBN)
+ {
+ //lets you find the book through the isbn number by iterating through the list
+ if (_bookList == null)
+ {
+ return null;
+ }
+ foreach (Book book in _bookList)
+ {
+ if (book.ISBN != null && book.ISBN.Equals(bookISBN))
+ {
+ return book;
+ }
+ }
+ return null;
+ }
+ public List GetAllBooks()
+ {
+ //returns the list of books
+ return _bookList;
+ }
+}
\ No newline at end of file
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/assetstatus.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/assetstatus.cs
new file mode 100644
index 0000000..efb1c97
--- /dev/null
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/assetstatus.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LibraryAppInteractive.businesslogic;
+//sets the enum values of the status of the book
+ public enum AssetStatus
+ {
+ Notavailable,
+ Available,
+ Loaned,
+ Reserved
+
+ }
+
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/booktype.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/booktype.cs
new file mode 100644
index 0000000..b79a8f2
--- /dev/null
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/booktype.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LibraryAppInteractive.businesslogic;
+//adds the values to the different types
+ public enum BookType
+ {
+ Paper = 1,
+ Digital
+ }
+
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/digitalbook.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/digitalbook.cs
new file mode 100644
index 0000000..faaac33
--- /dev/null
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/digitalbook.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LibraryAppInteractive.businesslogic;
+
+public class DigitalBook : Book
+{
+ private int _maxBorrowDays;
+ private float _latePenaltyPerDay;
+
+ public DigitalBook(string bookName, string bookISBN): base(bookName, bookISBN)
+ {
+ _maxBorrowDays = 15;
+ _latePenaltyPerDay = 5;
+ }
+
+ public void DetermineLoanLicense()
+ {
+ //adds the values for the max days and penalty
+ _maxBorrowDays = 15;
+ _latePenaltyPerDay = 5;
+ }
+
+ public override LibraryAsset BorrowBook()
+ {
+ //lets you borrow the book if its available
+ foreach (var asset in Assets)
+ {
+ if (asset.Status == AssetStatus.Available)
+ {
+ asset.Status = AssetStatus.Loaned;
+ asset.Loan = new LoanPeriod(DateTime.Now,DateTime.MinValue, _maxBorrowDays);
+ return asset;
+ }
+ }
+ return null;
+ }
+
+ public override (TimeSpan, int, decimal) ReturnBook(int libID)
+ {
+ //lets you return the book and returns the copy to the list and changes the status to available
+ var asset = findLibraryAsset(libID);
+ if (asset == null || asset.Status != AssetStatus.Loaned)
+ {
+ return (TimeSpan.Zero, 0, 0);
+ }
+ DateTime returnTime = DateTime.Now;
+
+ var loan = new LoanPeriod(asset.Loan.BorrowedOn, returnTime, _maxBorrowDays);
+ asset.Loan = loan;
+
+ asset.Status = AssetStatus.Available;
+ TimeSpan duration = loan.LoanDuration;
+ int lateDays = loan.LatePeriod.Days;
+ decimal penalty = lateDays * (decimal)_latePenaltyPerDay;
+
+ return (duration, lateDays, penalty);
+ }
+}
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/libraryasset.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/libraryasset.cs
new file mode 100644
index 0000000..02b02c4
--- /dev/null
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/libraryasset.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LibraryAppInteractive.businesslogic;
+
+public class LibraryAsset
+{
+ public Book _book;
+ public int _libID;
+ public LoanPeriod _loanPeriod;
+
+ public AssetStatus Status { get; set; }
+ public LoanPeriod Loan { get; set; }
+ public bool IsAvailable { get; }
+
+ public LibraryAsset(int libID, Book book)
+ {
+ //sets up the values for a asset of books
+ _libID = libID;
+ _book = book;
+ Status = AssetStatus.Available;
+ }
+}
+
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/loanperiod.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/loanperiod.cs
new file mode 100644
index 0000000..9f9b7e9
--- /dev/null
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/loanperiod.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LibraryAppInteractive.businesslogic;
+
+public struct LoanPeriod
+{
+ private DateTime _borrowedOn;
+ private DateTime _returnedOn;
+ private DateTime _dueDate;
+
+ public DateTime BorrowedOn
+ {
+ get
+ {
+ return _borrowedOn;
+ }
+ }
+ public DateTime ReturnedOn {
+ get
+ { return _returnedOn;
+ }
+ }
+ public DateTime DueDate {
+ get
+ {
+ return _dueDate;
+ }
+ }
+ public TimeSpan LoanDuration {
+ get
+ {
+ return _returnedOn - _borrowedOn;
+ }
+ }
+ public TimeSpan LatePeriod {
+ get
+ {
+ if (_returnedOn <= _dueDate)
+ {
+ return TimeSpan.Zero;
+ }
+
+ return _returnedOn - _dueDate;
+ }
+ }
+
+ public LoanPeriod(DateTime borrowedOn, DateTime returnedOn, int days)
+ {
+ //sets all the values for a loan period
+ _borrowedOn = borrowedOn;
+ _returnedOn = returnedOn;
+ _dueDate = borrowedOn.AddDays(days);
+
+
+ }
+}
+
diff --git a/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/paperbook.cs b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/paperbook.cs
new file mode 100644
index 0000000..ae9fbc2
--- /dev/null
+++ b/LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/businesslogic/paperbook.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LibraryAppInteractive.businesslogic;
+
+public class PaperBook : Book
+{
+ private const int _maxBorrowDays = 30;
+ private const float _latePenaltyPerDay = 0.25f;
+
+ public PaperBook(string bookName, string bookISBN): base(bookName, bookISBN)
+ {
+
+ }
+
+ public override LibraryAsset BorrowBook()
+ {
+ //lets you borrow a book if it it availble and then takes one out of the copies
+ foreach (var asset in Assets)
+ {
+ if (asset.Status == AssetStatus.Available)
+ {
+ asset.Status = AssetStatus.Loaned;
+ asset.Loan = new LoanPeriod(DateTime.Now, DateTime.MinValue, _maxBorrowDays);
+ return asset;
+ }
+ }
+ return null;
+ }
+
+ public override (TimeSpan, int, decimal) ReturnBook(int libID)
+ {
+ //lets you return a book and then the status goes avaible and adds it to the copy
+ var asset = findLibraryAsset(libID);
+ if (asset == null || asset.Status != AssetStatus.Loaned)
+ {
+ return (TimeSpan.Zero, 0, 0);
+ }
+ DateTime returnTime = DateTime.Now;
+
+ var loan = new LoanPeriod(asset.Loan.BorrowedOn, returnTime, _maxBorrowDays);
+ asset.Loan = loan;
+
+ asset.Status = AssetStatus.Available;
+ TimeSpan duration = loan.LoanDuration;
+ int lateDays = loan.LatePeriod.Days;
+ decimal penalty = lateDays * (decimal)_latePenaltyPerDay;
+
+ return (duration, lateDays, penalty);
+ }
+}
+