Asp.Net Core MVC web appplication using mssql, ef6, docker, jquery, sass, CORS, restAPI, socket, hubs & signalR, vanilla js, bootstrap library
Main catalog page where you can scroll and choose animel to explore and comment
pulling images to your local device: $ docker pull bloodshop/petshopapp:1.0 # https://hub.docker.com/repository/docker/bloodshop/petshopapp
$ docker pull bloodshop/petshopdb:1.0 # https://hub.docker.com/repository/docker/bloodshop/petshopdb
$ docker-compose up -d
version: '3.3'
services:
db:
image: bloodshop/petshopdb:1.0
restart: always
app:
depends_on:
- db
image: bloodshop/petshopapp:1.0
ports:
- "3000:80"
- "3001:433"
networks:
- db-bridge
restart: always
Lines 15 to 17 in bcf9df3
public class InfrastuctureServiceInstaller : IServiceInstaller
{
public void Install(IServiceCollection services, IConfiguration configuration)
{
services.AddTransient<IRepository, PetRepository>();
string connectionString = configuration["ConnectionStrings:DefaultConnection"];
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddControllersWithViews().AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = null;
});
services.AddDbContext<ICallCenterContext, PetDbContext>(options => options.UseLazyLoadingProxies().UseSqlServer(connectionString));
}
}
public interface IServiceInstaller
{
void Install(IServiceCollection services,IConfiguration configuration);
}
-
ViewModels & models
Models - pure models which are used in our database and repositories- Animal
- Category
- Comment
- AddAnimalViewModel
- AddCategoryViewModel
- AddCommentViewModel
- EditAnimalViewModel
- LoginViewModel
- ManageUsersViewModel
- RegisterViewModel
- SearchAnimalViewModel
examlpe viewmodel binded with form/view
Viewmodelpet-shop/ViewModels/SearchAnimalViewModel.cs
Lines 5 to 11 in bca1335
@{ var searchModel = new SearchAnimalViewModel(); }
pet-shop/Views/Shared/_Layout.cshtml
Lines 87 to 91 in bca1335
-
Initialize ASP.NET Identity
You can initialize ASP.NET Identity when the application starts. Since ASP.NET Identity is Entity Framework based in this sample,
you can create DatabaseInitializer which is configured to get called each time the app starts.
Please look in Program.cs
Lines 16 to 29 in bca1335
- Create user
- Create user with password
- Create Roles
- Add Users to Roles
-
Validation
When you create a User using a username or password, the Identity system performs validation on the username and password, and the passwords are hashed before they are
stored in the database. You can customize the validation by changing some of the properties of the validators such as Turn alphanumeric on/off, set minimum password length
or you can write your own custom validators and register them with the Administrator. You can use the same approach for UserManager and RoleManager.
- Look at Controllers\AccountController.cs Default Action on how to tweak the default settings for the Validators
- Look at Models\DataAnnotations\ValidateFileAttribute.cs to see how you can implement the different validators
- Look at Controllers\AccountController.cs Cutomize Action on how you can use the custom validators with the Managers
pet-shop/Models/DataAnnotations/ValidateFileAttribute.cs
Lines 5 to 38 in bca1335
- Register a user, Login Click Register and see the code in AccountController.cs and Register Action. Click Login and see the code in AccountController.cs and Login Action.
- Basic Role Management Do Create, Update, List and Delete Roles. Only Users In Role Admin can access this page. This uses the [Authorize] on the controller.
- Basic User Management Do Create, Update, List and Delete Users. Assign a Role to a User. Only Users In Role Admin can access this page. This uses the [Authorize] on the controller.
pet-shop/Hubs/CallCenterHub.cs
Lines 6 to 19 in 7948044
!!Importent!! -- Providing the CallsController that Hub implementing the `ICallCenterHub` interface inorder to get the dependencies (Dependency Injection).
$(() => {
LoadCallsData();
let $theWarning = $("#theWarning");
$theWarning.hide();
var connection = new signalR.HubConnectionBuilder().withUrl("/callcenter").build();
connection.start()
.then(() => connection.invoke("JoinCallCenters"))
.catch(err => console.error(err.toString()));
connection.on("NewCallReceivedAsync", () => LoadCallsData());
connection.on("CallDeletedAsync", () => LoadCallsData());
connection.on("CallEditedAsync", () => LoadCallsData());
function LoadCallsData() {
var tr = '';
$.ajax({
url: '/Calls/GetCalls',
method: 'GET',
success: (result) => {
$.each(result, (k, v) => {
tr += `<tr>
<td>${v.Name}</td>
<td>${v.Email}</td>
<td>${moment(v.CallTime).format("llll")}</td>
<td>
<a href="../Calls/Details?id=${v.Id}" class="btn btn-sm btn-success deatils-button" data-id="${v.Id}">Details</a>
<a href="../Calls/Edit?id=${v.Id}" class="btn btn-sm btn-danger edit-button" data-id="${v.Id}">Edit</a>
<a href="../Calls/Delete?id=${v.Id}" class="btn btn-sm btn-warning delete-button" data-id="${v.Id}">Delete</a>
</td>
</tr>`;
})
$("#logBody").html(tr);
},
error: (error) => {
$theWarning.text("Failed to get calls...");
$theWarning.show();
console.log(error)
}
});
}
});
pet-shop/wwwroot/js/theme-mode.js
Lines 1 to 33 in bca1335