Skip to content

Commit 79e9160

Browse files
committed
adding source code and updated M1 exercise instructions
1 parent 003b9db commit 79e9160

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2945
-53
lines changed

.github/workflows/LP1SampleApps.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This workflow is triggered on two events: workflow_dispatch and push.
2+
#
3+
# - The workflow_dispatch event allows you to manually trigger the workflow from GitHub's UI.
4+
# - The push event triggers the workflow whenever there's a push to the master branch, but only
5+
# if the changes include files in the LearnModuleExercises/SampleApps/** directory.
6+
#
7+
# The defaults section sets the default shell for all run commands in the workflow to PowerShell (pwsh).
8+
#
9+
# The workflow consists of a single job named create_zip, which runs on the latest version of Ubuntu.
10+
#
11+
# This job has three steps:
12+
#
13+
# 1. The Checkout step uses the actions/checkout@v4 action to checkout the repository's code onto the
14+
# runner. This is a common first step in most workflows as it allows subsequent steps to operate on
15+
# the codebase.
16+
#
17+
# 2. The Create SampleApps zip step changes the current directory to ./LearnModuleExercises/SampleApps
18+
# and then creates a zip file of all the files in that directory, including those in the .vscode
19+
# subdirectory. The -r option is used to zip directories recursively and the -q option is used to run
20+
# the command quietly without printing a lot of output. The resulting zip file is saved in the
21+
# ../Downloads directory with the name SampleApps.zip.
22+
#
23+
# 3. The Commit and push step uses the Endbug/add-and-commit@v7 action to add the newly created zip file
24+
# to the repository, commit the changes with the message 'Updating Zip for API source files', and then
25+
# push the changes back to the repository. The add input is set to the path of the zip file and the push
26+
# input is set to true to enable pushing.
27+
#
28+
# This workflow is useful for automatically packaging and versioning sample applications whenever changes
29+
# are made to them.
30+
#
31+
name: CreateAZ2007M2SamplesZip
32+
on:
33+
workflow_dispatch:
34+
push:
35+
branches:
36+
- 'main'
37+
paths:
38+
- DownloadableCodeProjects/az-2007-m2-explain-document/**
39+
40+
defaults:
41+
run:
42+
shell: pwsh
43+
44+
jobs:
45+
create_zip:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
- name: Create LP1 SampleApps zip
51+
run: |
52+
cd ./DownloadableCodeProjects/az-2007-m2-explain-document
53+
rm -f ../Downloads/AZ2007M2SamplesZip.zip
54+
zip -r -q ../Downloads/AZ2007M2SamplesZip.zip $(git ls-files)
55+
- name: Commit and push
56+
uses: Endbug/add-and-commit@v7
57+
with:
58+
add: '["DownloadableCodeProjects/Downloads/AZ2007M2SamplesZip.zip"]'
59+
message: 'Updating Zip with sample app source files'
60+
push: true

.gitignore

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2+
[Bb]in/
3+
[Oo]bj/
4+
5+
# mstest test results
6+
TestResults
7+
8+
## VSCode
9+
.vscode/*
10+
11+
## Ignore Visual Studio temporary files, build results, and
12+
## files generated by popular Visual Studio add-ons.
13+
14+
# User-specific files
15+
*.suo
16+
*.user
17+
*.sln.docstates
18+
19+
# Include dlls if theyfre in the NuGet packages directory
20+
!/packages/*/lib/*.dll
21+
!/packages/*/lib/*/*.dll
22+
# Include dlls if they're in the CommonReferences directory
23+
!*CommonReferences/*.dll
24+
25+
# Build results
26+
[Dd]ebug/
27+
[Rr]elease/
28+
x64/
29+
*_i.c
30+
*_p.c
31+
*.ilk
32+
*.meta
33+
*.obj
34+
*.pch
35+
*.pdb
36+
*.pgc
37+
*.pgd
38+
*.rsp
39+
*.sbr
40+
*.tlb
41+
*.tli
42+
*.tlh
43+
*.tmp
44+
*.log
45+
*.vspscc
46+
*.vssscc
47+
*.sln
48+
.builds
49+
50+
# Visual C++ cache files
51+
ipch/
52+
*.aps
53+
*.ncb
54+
*.opensdf
55+
*.sdf
56+
57+
# Visual Studio profiler
58+
*.psess
59+
*.vsp
60+
*.vspx
61+
62+
# Guidance Automation Toolkit
63+
*.gpState
64+
65+
# ReSharper is a .NET coding add-in
66+
_ReSharper*
67+
68+
# NCrunch
69+
*.ncrunch*
70+
.*crunch*.local.xml
71+
72+
# Installshield output folder
73+
[Ee]xpress
74+
75+
# DocProject is a documentation generator add-in
76+
DocProject/buildhelp/
77+
DocProject/Help/*.HxT
78+
DocProject/Help/*.HxC
79+
DocProject/Help/*.hhc
80+
DocProject/Help/*.hhk
81+
DocProject/Help/*.hhp
82+
DocProject/Help/Html2
83+
DocProject/Help/html
84+
85+
# Click-Once directory
86+
publish
87+
88+
# Publish Web Output
89+
*.Publish.xml
90+
91+
# NuGet Packages Directory
92+
# packages
93+
94+
# Windows Azure Build Output
95+
csx
96+
*.build.csdef
97+
98+
# Windows Store app package directory
99+
AppPackages/
100+
101+
# Others
102+
[Bb]in
103+
[Oo]bj
104+
sql
105+
TestResults
106+
[Tt]est[Rr]esult*
107+
*.[Cc]ache
108+
*.editorconfig
109+
ClientBin
110+
[Ss]tyle[Cc]op.*
111+
~$*
112+
*.dbmdl
113+
Generated_Code #added for RIA/Silverlight projects
114+
115+
# Backup & report files from converting an old project file to a newer
116+
# Visual Studio version. Backup files are not needed, because we have git ;-)
117+
_UpgradeReport_Files/
118+
Backup*/
119+
UpgradeLog*.XML
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
placeholder
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
placeholder
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Library.ApplicationCore.Entities;
2+
3+
public class Author
4+
{
5+
public int Id { get; set; }
6+
public required string Name { get; set; }
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Library.ApplicationCore.Entities;
2+
3+
public class Book
4+
{
5+
public int Id { get; set; }
6+
public required string Title { get; set; }
7+
public int AuthorId { get; set; }
8+
public required string Genre { get; set; }
9+
public required string ImageName { get; set; }
10+
public required string ISBN { get; set; }
11+
public Author? Author { get; set; }
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Library.ApplicationCore.Entities;
2+
3+
public class BookItem
4+
{
5+
public int Id { get; set; }
6+
public int BookId { get; set; }
7+
public DateTime AcquisitionDate { get; set; }
8+
public string? Condition { get; set; }
9+
public Book? Book { get; set; }
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Library.ApplicationCore.Entities;
2+
3+
public class Loan
4+
{
5+
public int Id { get; set; }
6+
public int BookItemId { get; set; }
7+
public int PatronId { get; set; }
8+
public Patron? Patron { get; set; }
9+
public DateTime LoanDate { get; set; }
10+
public DateTime DueDate { get; set; }
11+
public DateTime? ReturnDate { get; set; }
12+
public BookItem? BookItem { get; set; }
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Library.ApplicationCore.Entities;
2+
3+
public class Patron
4+
{
5+
public int Id { get; set; }
6+
public required string Name { get; set; }
7+
public DateTime MembershipEnd { get; set; }
8+
public DateTime MembershipStart { get; set; }
9+
public string? ImageName { get; set; }
10+
public ICollection<Loan> Loans { get; set; } = new HashSet<Loan>();
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.ComponentModel;
2+
using System.Reflection;
3+
4+
namespace Library.ApplicationCore.Enums;
5+
6+
public static class EnumHelper
7+
{
8+
public static string GetDescription(Enum value)
9+
{
10+
if (value == null)
11+
return string.Empty;
12+
13+
FieldInfo fieldInfo = value.GetType().GetField(value.ToString())!;
14+
15+
DescriptionAttribute[] attributes =
16+
(DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
17+
18+
if (attributes != null && attributes.Length > 0)
19+
{
20+
return attributes[0].Description;
21+
}
22+
else
23+
{
24+
return value.ToString();
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.ComponentModel;
2+
3+
namespace Library.ApplicationCore.Enums;
4+
5+
public enum LoanExtensionStatus
6+
{
7+
[Description("Book loan extension was successful.")]
8+
Success,
9+
10+
[Description("Loan not found.")]
11+
LoanNotFound,
12+
13+
[Description("Cannot extend book loan as it already has expired. Return the book instead.")]
14+
LoanExpired,
15+
16+
[Description("Cannot extend book loan due to expired patron's membership.")]
17+
MembershipExpired,
18+
19+
[Description("Cannot extend book loan as the book is already returned.")]
20+
LoanReturned,
21+
22+
[Description("Cannot extend book loan due to an error.")]
23+
Error
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.ComponentModel;
2+
3+
namespace Library.ApplicationCore.Enums;
4+
5+
public enum LoanReturnStatus
6+
{
7+
[Description("Book was successfully returned.")]
8+
Success,
9+
10+
[Description("Loan not found.")]
11+
LoanNotFound,
12+
13+
[Description("Cannot return book as the book is already returned.")]
14+
AlreadyReturned,
15+
16+
[Description("Cannot return book due to an error.")]
17+
Error
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.ComponentModel;
2+
3+
namespace Library.ApplicationCore.Enums;
4+
5+
public enum MembershipRenewalStatus
6+
{
7+
[Description("Membership renewal was successful.")]
8+
Success,
9+
10+
[Description("Patron not found.")]
11+
PatronNotFound,
12+
13+
[Description("It is too early to renew the membership.")]
14+
TooEarlyToRenew,
15+
16+
[Description("Cannot renew membership due to an outstanding loan.")]
17+
LoanNotReturned,
18+
19+
[Description("Cannot renew membership due to an error.")]
20+
Error
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Library.ApplicationCore.Entities;
2+
3+
namespace Library.ApplicationCore;
4+
5+
public interface ILoanRepository {
6+
Task<Loan?> GetLoan(int loanId);
7+
Task UpdateLoan(Loan loan);
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Library.ApplicationCore.Enums;
2+
3+
public interface ILoanService
4+
{
5+
Task<LoanReturnStatus> ReturnLoan(int loanId);
6+
Task<LoanExtensionStatus> ExtendLoan(int loanId);
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Library.ApplicationCore.Entities;
2+
3+
namespace Library.ApplicationCore;
4+
5+
public interface IPatronRepository {
6+
Task<Patron?> GetPatron(int patronId);
7+
Task<List<Patron>> SearchPatrons(string searchInput);
8+
Task UpdatePatron(Patron patron);
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using Library.ApplicationCore.Enums;
2+
3+
public interface IPatronService
4+
{
5+
Task<MembershipRenewalStatus> RenewMembership(int patronId);
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)