1
300583/300902
Web Development Project
Due: 8pm, Fri 2 Nov 2018
This project is to build a website for the imaginary Western Sydney Hotel (WSH) which allows
customers to search and book rooms, and administrators to manage bookings and view statistics, etc. You
are suggested to read the entire specification first, and then start with the tasks that are already covered by
our lectures.
Before starting this project, make sure the Visual Studio (VS) you use is of version XXXXXXXXXXIf not, you
should follow the link https:
docs.microsoft.com/en-us/visualstudio/productinfo/installing-an-earlier-
elease-of-vs2017 to get it installed. This is required, as different versions of VSes behave differently. Our
instructions below are only tested to work with v15.7.6, and VS v15.8 is known to not work this way.
1 Creating project in Visual Studio (VS)
Since the project needs to support authentication for customers and administrators, it needs the ASP.NET
Core Identity (a package for authentication) in the very beginning. To include this package in your project,
you need to set up the authentication when you create the project in VS. This can be easily done by
following the steps below:
a. Select File > New > Project.
. Select ASP.NET Core Web Application. Name the project “WebHotel”.
c. Select “Web Application (Model-View-Controller)”, then select Change Authentication.
d. Select “Individual User Accounts” and click OK.
Then, you’ll have an authentication system automatically implemented in your project. Since the
Identity package by default uses SQL Server LocalDB to store user names and passwords, you need to
https:
docs.microsoft.com/en-us/visualstudio/productinfo/installing-an-earlier-release-of-vs2017
https:
docs.microsoft.com/en-us/visualstudio/productinfo/installing-an-earlier-release-of-vs2017
2
change this to SQLite. As you learned before, you can achieve this by changing the DbContext in the
ConfigureServices() method in the Startup.cs file (See the screenshot below). Specifically, change
to
You can name this database file "WSH.db". In this project, you are going to use it to store data not only for
authentication, but also for the Western Sydney Hotel.
At this stage, the database file WSH.db has not been created yet. You need to use migration to create it.
Fortunately, when you created this project with authentication enabled, the migration for creating this
database is already created for you under the 'Data/Migrations' folder. What you need to do is to simply run
the 'Update-Database' command in Package Manager Console. Then, you'll see the WSH.db file is created
for you.
Finally, you can now compile and run this project. You'll see the Register and Login links appear in the
ight of the navigation bar. Note that, in ASP.NET Core Identity, a user's email address is used as his/her
user name.
2 Two roles of administrators and customers
Besides maintaining users’ credentials, the Identity package can also assign users with different roles.
You are required to use this package to divide the users of this website into two roles: administrators and
customers. You should create only one user with the 'administrators' role, and set up his/her username to be
' XXXXXXXXXX' and his/her password to be 'P@ssw0rd' when the web application starts. On the other
hand, all users registering into the website by clicking the 'Register' link mentioned in the Section 3 below
should be assigned the 'customers' role.
Moreover, source code should be added to the Views/Shared/_Layout.cshtml file such that, after logging
in, administrators and customers only see links that they should have access to in the navigation bar. (see the
details in the Section 3 below)
NB: We will discuss the above in our Lecture 11. You can start to implement them after lecture 11.
3 Navigation and layout
Each page should have a navigation bar in the top, with the same ‘look and feel’ among all pages. This
should be achieved by using _Layout.cshtml and Bootstrap.
The links contained in the navigation bar should be dynamic. The detailed requirements are as follows:
• The links for non-logged-in visitors should include the following: Home, Register, and Login. Note
that the Login link here is used by both customers and administrators. You should add source code
to your project to determine the role of a logged-in user.
• The links for logged-in customers should include the following: Home, My Details, Search Rooms,
Book A Room, My Bookings and Logout.
• The links for logged-in administrators should include the following: Home, Manage Bookings,
Statistics and Logout.
Note: How to make the links dynamic will be discussed in Lecture 11. You can start with include all the
links in the navigation bar, and make them dynamic after Lecture 11.
4 Home page
The Home link in the navigation bar leads to this page, which should display:
3
• A carousel below the navigation bar. This carousel should rotate four pictures about the WSH. The
pictures can be about building, rooms, dining, etc. and can be downloaded from Internet and then
modified. Each picture needs to have a caption.
• Two columns below the carousel. The left column should display a welcome message and a
ief
introduction to the hotel. The right column should display a list of useful links for the Great Western
Sydney area (e.g., a link to Pa
amatta/Penrith/Campbelltown weather, a link to
Pa
amatta/Penrith/Campbelltown city council, etc.). The two columns should stack up when the
viewport width is less than that of a small screen.
5 Models
This website should use the following three Model classes. Each class has certain properties. The
equirements to these properties are also described below. You should apply appropriate data types and data
annotations to fulfil these requirements.
You should fully create the Model classes first, and then scaffolding them one by one, and then migrate
them to database. You are suggested to do these after our lecture 8.
NB: During scaffolding, you should choose the ApplicationDbContext used by Identity as the
DbContext (i.e., use the same database as used by Identity.) During migration, if you see the complaint that
SQLite does not support the migration operation 'AddForeignKeyOperation', you should comment out the
migration code in the Up() and Down() methods related to 'ForeignKey'. These two methods can be found in
the .cs file under the 'Migrations' folder. Specially, you should comment out the following from the Up():
And comment out the following from the Down():
After commenting out the above code, the migration should be successful. Note that the above operations
elated to 'ForeignKey' are not necessary at all.
5.1 Room.cs
The Room class models the rooms in WSH. It should have the following properties.
Property Data Type Requirement
ID int Primary key;
Level string Meaning the level of this room; Exactly one character of ‘G’,
‘1’, ‘2’, or ‘3’. Required.
BedCount int Meaning the number of beds in the room; can only be 1, 2, or
3.
Price decimal Meaning the price per night; should be between $50 and
$300.
TheBookings ICollection
This is a navigation property (Note: will be discussed in
4
lecture 8; see
https:
www.learnentityframeworkcore.com
elationships )
After scaffolding and migrating this class into database, you should use the https:
localhost:xxx/Rooms
interface to populate the Room table with the following data. (NB: to provide convenience to our marking,
you must use the data below.)
ID Level BedCount Price
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
13 G XXXXXXXXXX
14 G XXXXXXXXXX
15 G XXXXXXXXXX
16 G XXXXXXXXXX
5.2 Customer.cs
The Customer class models all customers who have ever registered with WSH. It should have the
following properties.
Property Data Type Requirement
Email string Primary key; Required; Valid email address; Since its name
doesn't follow the convention to be the primary key, you
should add the [Key] annotation to indicate that this property
is the primary key, and also add the
[DatabaseGenerated(DatabaseGeneratedOption.None)]
annotation to prevent its value from being automatically
generated by database.
Surname string Required; Length ranges between 2 and 20 characters
inclusive; Can only consist of English letters, hyphen and
apostrophe.
GivenName string Same as above.
Postcode string Required; exactly 4 digits.
TheBookings ICollection This is a navigation property (Note: will be discussed in
lecture 8)
Notes:
• This class has no property for password. Customers' passwords will be automatically managed by the
ASP.NET Identity package, and will not be stored here.
https:
www.learnentityframeworkcore.com
elationships
https:
localhost:xxx/Rooms
5
• You should use the 'Register' link in the website to register a customer into the website, and then use the
'My Details' link (described in Section 6) to enter the details for this customer. Do this for at least 10
customers with some common postcodes to allow the 'Statistics' link to show results.
5.3 Booking.cs
The Booking class models all bookings ever made by customers with WSH. It should have the following
properties.
Property Data Type Requirement
ID int Primary key;
RoomID int Foreign Key (NB: since the name follows convention, this will