PrimeHotel – how to run this project

In this post, I will guide you through the process of downloading and running my project – PrimeHotel. It is a project created for learning purposes so you are free to contribute, clone, and use it for any non-commercial activity.

It is a medium-sized service, that represents a hotel management system. Is holds user reservations, user profiles and saves them in the MS SQL database. It can also connect to a 3-rd party weather service to fetch current weather. More features are yet to come, which will show more .NET integrations and capabilities, good practices, and some awesome features.

If you are new to .NET, please take a look at this post first: .NET 5 – How to start. It will help you with making your first steps.

Download the project

PrimeHotel is a .NET 5 project that uses ASP.NET Core and Entity Framework Core 5. It is hosted on GitHub, so you can go ahead and navigate to this link: https://github.com/mikuam/PrimeHotel

Make sure you have Git installed on your machine. Then you can clone the project by using a command in a console terminal.

Now open the project with your favorite IDE like Visual Studio or Visual Studio Code.

I’m using Visual Studio 2019 and on my machine, it looks like this.

Let’s now have a quick look at the project structure:

  • Clients – this is where are classes that communicate with other services with HttpClient
  • Controllers – here are all controller classes containing all the endpoints in this service
  • Data – repository classes that encapsulate SQL commands – currently Dapper
  • Migrations – Entity Framework Core 5 migrations, that keeps the database schema changes
  • Models – Entity Framework Core 5 classes, that represent tables in the database 

Configure the database

For learning purposes, it will be best to set up a SQL Server on your machine. This is what I’m doing. However, if you would like to set it up as a docker image, you can read my post about it: Set up a SQL Server in a docker container.

You can download a SQL Server Express version for free from the Microsoft website. Once you install and set up a server, it would be available probably with the localhost address. Try to connect to your SQL Server and check if you have a PrimeHotel database created. For connecting I’m using Azure Data Studio – an awesome and fast tool, great for simple actions.

If you don’t have a PrimeHotel database, just create it and leave it empty.

The last part is to update a connection string in our project. Go ahead and edit appsettings.json file. It looks like this:

The connection string might differ slightly, mine is:

Instead of localhost you could also have something as localhost\SQLEXPRESS, but that is your individual configuration of SQL Server.

Running the project

When you have everything in place, just go ahead and run the project. If everything is set-up and .NET 5 runtime and SDK are installed, you should be good.

In Visual Studio just press F5. In Visual Studio Code open the terminal and write two commands: dotnet build and dotnet run. Then when navigating to a given URL, you should see something like this:

Simple, right? Congratulation on running the project. Now you are good to go for coding and improving this service.

Good luck!

 

2 thoughts on “PrimeHotel – how to run this project

    1. Hi Majid,
      Yeah, I was thinking about what pattern to choose when creating this project, but I decided to do it as easy and compact as possible. With that approach, most of the logic is in controllers so it’s easy to find and understand. With Clean Architecture I would need to create separate projects, which I think is not worth it in this case. However, I like this pattern, but I’d rather use it in medium-sized services.

Leave a Reply

Your email address will not be published. Required fields are marked *