Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
x:Class="LibraryAppInteractive.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:LibraryAppInteractive"
Shell.FlyoutBehavior="Disabled">

<TabBar>
<Tab Title="Browse" Icon="library.png">
<ShellContent
ContentTemplate="{DataTemplate local:LibraryBrowsePage}"
x:Name="BrowseShellContent"
Route="LibraryBrowsePage" />
</Tab>
<Tab Title="Admin" Icon="admin.png">
<ShellContent
ContentTemplate="{DataTemplate local:LibraryAdminPage}"
Route="LibraryAdminPage" />
x:Name="AdminShellContent"
Route="LibraryAdminPage" />
</Tab>
</TabBar>

</Shell>
</Shell>
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
namespace LibraryAppInteractive;
using LibraryAppInteractive.BusinessLogic;

namespace LibraryAppInteractive;

public partial class AppShell : Shell
{
private Library _library;

public AppShell()
{
InitializeComponent();

_library = new Library();

BrowseShellContent.Content = new LibraryBrowsePage(_library);
AdminShellContent.Content = new LibraryAdminPage(_library);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace LibraryAppInteractive.BusinessLogic
{
public enum AssetStatus
{
NotAvailable = 1,
Available,
Loaned,
Reserved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace LibraryAppInteractive.BusinessLogic
{
public enum BookType
{
Paper = 1,
Digital,
Audio
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace LibraryAppInteractive.BusinessLogic
{
public class DigitalBook : Book
{
#region Fields
private const int _maxBorrowDays = 21;
private const decimal _latePenaltyPerDay = 0.25m;
#endregion

#region Constructors
public DigitalBook(string bookName, string bookISBN) : base(bookName, bookISBN)
{

}

#endregion

#region Properties

#endregion

#region Methods
// private DetermineLoanLicense()


public override LibraryAsset BorrowBook()
{
LibraryAsset asset = base.BorrowBook();

if (asset != null)
{
asset.Loan = new LoanPeriod();
asset.Loan.BorrowedOn = DateTime.Now;
asset.Loan.DueDate = DateTime.Now.AddDays(_maxBorrowDays);
asset.Loan.ReturnedOn = DateTime.MinValue;

}

return asset;
}
public override (TimeSpan, int, decimal) ReturnBook(int libID)
{
LibraryAsset asset = _libAssetList.FirstOrDefault(iAsset => iAsset.LibraryID == libID);
if (asset != null)
{
asset.Loan.ReturnedOn = DateTime.Now;
asset.Status = AssetStatus.Available;

TimeSpan latePeriod = asset.Loan.LatePeriod;
int lateDays = latePeriod.Days;
decimal penalty = lateDays * _latePenaltyPerDay;

return (latePeriod, lateDays, penalty);
}
return (TimeSpan.Zero, 0, 0m);
}
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;

namespace LibraryAppInteractive.BusinessLogic
{
public class Library
{
#region Fields
private List<Book> _bookList;
private int _libIDGeneratorSeed;
private const int DEFAULT_LIBID_START = 100;
#endregion

#region Constructors
public Library()
{
_bookList = new List<Book>();
_libIDGeneratorSeed = DEFAULT_LIBID_START;
CreateDefaultBook();
}
#endregion

#region Properties
public IEnumerable<Book> Books
{
get { return _bookList; }
}
#endregion

#region Methods

private int DetermineLibID()
{
int nextID = _libIDGeneratorSeed;
_libIDGeneratorSeed++;
return nextID;
}

private void CreateDefaultBook()
{
// Book 1
Book sum = new PaperBook("The Summoning", "9780385665346");
sum.Authors.Add("Kelly Armstrong");

for (int i = 0; i < 3; i++) // number of copies
{
int id = DetermineLibID();
LibraryAsset asset = new LibraryAsset(id, sum);
sum.AddAsset(asset);
}
_bookList.Add(sum);

// Book 2
Book gobSlay = new PaperBook("Goblin Slayer, Manga Volume 1", "9780316439725");
gobSlay.Authors.Add("Kumo Kagyu");

for (int i = 0; i < 2; i++)
{
int id = DetermineLibID();
LibraryAsset asset = new LibraryAsset(id, gobSlay);
gobSlay.AddAsset(asset);
}
_bookList.Add(gobSlay);

// Book 3
Book shield = new DigitalBook("Rising of the Shield Hero, Volume 1, Light novel", "9781935548645");
shield.Authors.Add("Aneko Yusagi");

for (int i = 0; i < 2; i++)
{
int id = DetermineLibID();
LibraryAsset asset = new LibraryAsset(id, shield);
shield.AddAsset(asset);
}
_bookList.Add(shield);
}

public Book RegisterBook(string bookName, string bookISBN, string authors, BookType bookType, int nCopies)
{
Book newBook;

if (bookType == BookType.Paper)
{
newBook = new PaperBook(bookName, bookISBN);
}
else
{
newBook = new DigitalBook(bookName, bookISBN);
}

newBook.Authors.Add(authors);

for (int iAsset = 0; iAsset < nCopies; iAsset++)
{
LibraryAsset asset = new LibraryAsset(DetermineLibID(), newBook);
newBook.AddAsset(asset);
}

_bookList.Add(newBook);
return newBook;
}

public List<Book> FindBooksByName(string bookName)
{
return _bookList
.Where(book => book.Name != null &&
book.Name.Contains(bookName, StringComparison.OrdinalIgnoreCase))
.ToList();
}

public Book FindBookByISBN(string bookISBN)
{
return _bookList.FirstOrDefault(book => book.ISBN == bookISBN);
}
public Book FindBookByAssetID(int libID)
{
return _bookList.FirstOrDefault(book =>
book.Assets.Any(asset => asset.LibraryID == libID));
}
#endregion
}
}
Loading