This web application is built using Asp.Net Core MVC and utilizes an MSSQL Docker image with Entity Framework 7, Identity, and Bootstrap. The app allows users to scroll through and choose animals to explore and leave comments.
Main catalog where you can scroll choose animel and comment
The app demonstrates the use of the MVC pattern and including:
- Asp.NetCore MVC server which is animel catalog web application
- MSSQL server runs on docker images from microsoft using this command :
docker run -e "ACCEPT_EULA=Y" --name db --network petshop-bridge -e "MSSQL_SA_PASSWORD=1234ABCD@" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-CU14-ubuntu-20.04
- netwrok bridge called db-bridge
This app includes Docker-file and Docker-Compose which works with images that i already published
docker pull itayg98/zoo-app:1.2
docker pull itayg98/zoo-db:1.2
It is very important to add an apropriate connection string using the MSSQL containers name , port and add TCP :
Zoo-Catalog-App/Zoo-Blog-master/Zoo/appsettings.json
Lines 9 to 12 in 9667d1c
Zoo-Catalog-App/Zoo-Blog-master/docker-compose.yml
Lines 1 to 27 in e4a3254
MSSQL Diagram
My model contain 3 objects : Category ,Animal and Comment. I gave each of them several propetries and fitting validation attributes including Regex patterns, Data type custom messege errors etc.. I created two custom Vlidation Attributes:
- Birthdate to validate the animal is less than 150 years and was born in the current day or earlier
- File validator to check wether if the file's content Type include the word "Image" and the size of the file limited to 10MB
In order to generate the categories i made an Enum helper model which is not mapped in to the DataBase but i use to generate apropriate select tag
The model project contains also the data access layer Generic base Repsoitory class for each entity whom id is of type Guid and one service of image formating which help me to save the images files as bytes array and generate the image back on the client side
Zoo-Catalog-App/Zoo-Blog-master/Model/Services/ImagesFormater.cs
Lines 29 to 39 in 4a882f1
Zoo-Catalog-App/Zoo-Blog-master/Model/Services/ImagesFormater.cs
Lines 83 to 90 in 4a882f1
I've created several views for the controllers, one view component and 3 usefull partial view for layout styles and scripts and nav bar The nav bar is used to navigate between the diffrent views and actions
The app's nav bar
The manager view of Create and update contain a vannila JS validation of the file type and it size in order to prevent the browser to throw an error
This project contain 4 controllers :
- Home - displaying the two most commented animals
- Manager - Handling the CRUD operation on the animals data
- Catalog - view the animals in the blog and can sort them by category
- Animel Data - Explore the animals details and allow the user to leave a comment. The comment posting uses Fetch api in order to prevent the page to relload each time the user post a comment.
Zoo-Catalog-App/Zoo-Blog-master/Zoo/wwwroot/Scripts/CommentFetch.js
Lines 48 to 64 in fa2e0fc
Hello world comment
I used Identity Nuget and seperate context in order to authenticate and authorize users in my web application and registering and loging in handels by model helpers named LoginModel and SignUpModel In the app there are 3 types of users "Admin" , "User" adn Anonymous . The manager role can use the Manager controller and has anchor nav-link to creation and update . every signed user can comment on animals in the application (including managers). Anonymous user can only scroll through the animels catalog page or Register/Log In.
Registering action :
Zoo-Catalog-App/Zoo-Blog-master/Zoo/Controllers/UserController.cs
Lines 49 to 74 in fa2e0fc
This web app solution includes one Xunit project of testing for the repository layer checking and validating the ReposiroeyBase class for both sync and async methods .
Test example :
Zoo-Catalog-App/Zoo-Blog-master/UnitTesting/AsyncRepositoryTest.cs
Lines 129 to 144 in fa2e0fc