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
12 changes: 0 additions & 12 deletions LibraryApp_Interactive/LibraryAppInteractive/LibraryApp/Library.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
x:Class="LibraryAppInteractive.LibraryAdminPage"
Title="Manage Book Assets">
<ContentPage.Content>
<Label Text="Library Admin page for the Interactive Library App"
HorizontalOptions="Center"
VerticalOptions="Center"/>
<VerticalStackLayout>
<Entry x:Name="_txtName" Placeholder="Enter book name"/>
<Entry x:Name="_txtIsbn" Placeholder="Enter book isbn"/>
<Entry x:Name="_txtAuthor" Placeholder="Enter author"/>
<Entry x:Name="_txtType" Placeholder="Enter type (paper or digital)"/>
<Button x:Name="_btnRegister" Clicked="RegisterBook" Text="Register"/>
<Button x:Name="_btnDisplay" Clicked="DisplayBooks" Text="Display"/>
</VerticalStackLayout>
</ContentPage.Content>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using LibraryAppInteractive.businesslogic;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4"/>
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128"/>
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*"/>
<MauiImage Update="Resources\Images\admin.svg" BaseSize="24,24"/>
<MauiImage Update="Resources\Images\library.svg" BaseSize="24,24"/>
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\admin.svg" BaseSize="24,24" />
<MauiImage Update="Resources\Images\library.svg" BaseSize="24,24" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*"/>
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)"/>
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LibraryAppInteractive.LibraryBrowsePage"
Title="Browse Interactive Library">

<Label Text="Browse Library page for the Interactive Library App"
HorizontalOptions="Center"
VerticalOptions="Center"/>

<VerticalStackLayout>
<Entry x:Name="_txtbookname" Placeholder="Enter book name"/>
<Button x:Name="_btnSearch" Clicked="SearchBook" Text="Search"/>
<Entry x:Name="_txtISBN" Placeholder="Enter book isbn number"/>
<Button x:Name="_btnBorrow" Clicked="BorrowBook" Text="Borrow"/>
<Entry x:Name="_txtLibID" Placeholder="Enter library ID"/>
<Button x:Name="_btnReturn" Clicked="OnReturnBook" Text="Return"/>
</VerticalStackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using LibraryAppInteractive.businesslogic;
using System.Collections.Immutable;

namespace LibraryAppInteractive;

Expand All @@ -14,7 +15,10 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

builder.Services.AddSingleton<Library>();

builder.Services.AddTransient<LibraryBrowsePage>();
builder.Services.AddTransient<LibraryAdminPage>();
return builder.Build();
}
}
Loading