├── .vscode
├── launch.json
└── tasks.json
├── APIFuelStation.csproj
├── CommandBus
├── CommandHandlers
│ ├── Auth
│ │ ├── AuthCommandHandler.cs
│ │ └── UserRegisterCommandHandler.cs
│ ├── Department
│ │ ├── CreateDepartmentHandler.cs
│ │ ├── DeleteDepartmentHandler.cs
│ │ └── UpdateDepartmentHandler.cs
│ ├── Designation
│ │ ├── CreateDesignationHandler.cs
│ │ ├── DeleteDesignationHandler.cs
│ │ └── UpdateDesignationHandler.cs
│ ├── Employee
│ │ ├── CreateEmployeeHandler.cs
│ │ ├── DeleteEmployeeHandler.cs
│ │ └── UpdateEmployeeHandler.cs
│ └── User
│ │ ├── CreateUserHandler.cs
│ │ ├── DeleteUserHandler.cs
│ │ └── UpdateUserHandler.cs
└── Commands
│ ├── Auth
│ ├── UserAuthCommand.cs
│ └── UserRegisterCommand.cs
│ ├── Department
│ ├── CreateDepartmentCommand.cs
│ ├── DeleteDepartmentCommand.cs
│ └── UpdateDepartmentCommand.cs
│ ├── Designation
│ ├── CreateDesignationCommand.cs
│ ├── DeleteDesignationCommand.cs
│ └── UpdateDesignationCommand.cs
│ ├── Employee
│ ├── CreateEmployeeCommand.cs
│ ├── DeleteEmployeeCommand.cs
│ └── UpdateEmployeeCommand.cs
│ └── User
│ ├── CreateUserCommand.cs
│ ├── DeleteUserCommand.cs
│ └── UpdateUserCommand.cs
├── Controllers
├── AuthController.cs
├── DepartmentsController.cs
├── DesignationsController.cs
├── DummyControllerExample.cs
├── EmployeesController.cs
├── UsersController.cs
└── WeatherForecastController.cs
├── DbContexts
└── FuelDBContext.cs
├── IRepositories
├── IAuthRepository.cs
├── IDepartmentRepository.cs
├── IDesignationRepository.cs
├── IEmployeeRepository.cs
└── IUserRepository.cs
├── Migrations
├── 20200619131033_UserTableMigration.Designer.cs
├── 20200619131033_UserTableMigration.cs
├── 20200620044643_UniqueEmail.Designer.cs
├── 20200620044643_UniqueEmail.cs
├── 20200620045532_UniquePhoneUsername.Designer.cs
├── 20200620045532_UniquePhoneUsername.cs
├── 20200620070410_DepartmentDesignationMigration.Designer.cs
├── 20200620070410_DepartmentDesignationMigration.cs
├── 20200623152632_EmployeeMigration.Designer.cs
├── 20200623152632_EmployeeMigration.cs
└── FuelDBContextModelSnapshot.cs
├── Models
├── Department.cs
├── Designation.cs
├── Employee.cs
└── User.cs
├── ModelsValidator
├── DepartmentValidator.cs
├── DesignationValidator.cs
├── EmployeeValidator.cs
└── UserValidator.cs
├── Program.cs
├── Properties
└── launchSettings.json
├── QueryBus
├── Queries
│ ├── Department
│ │ ├── GetAllDepartmentQuery.cs
│ │ └── GetSingleDepartmentQuery.cs
│ ├── Designation
│ │ ├── GetAllDesignationQuery.cs
│ │ └── GetSingleDesignationQuery.cs
│ ├── Employee
│ │ ├── GetAllEmployeeQuery.cs
│ │ └── GetSingleEmployeeQuery.cs
│ └── User
│ │ ├── GetAllUserQuery.cs
│ │ └── GetSingleUserQuery.cs
└── QueryHandlers
│ ├── Department
│ ├── GetAllDepartmentHandler.cs
│ └── GetSingleDepartmentHandler.cs
│ ├── Designation
│ ├── GetAllDesignationHandler.cs
│ └── GetSingleDesignationHandler.cs
│ ├── Employee
│ ├── GetAllEmployeeHandler.cs
│ └── GetSingleEmployeeHandler.cs
│ └── User
│ ├── GetAllUserHandler.cs
│ └── GetSingleUserHandler.cs
├── README.md
├── Repositories
├── DepartmentRepository.cs
├── DesignationRepository.cs
├── EmployeeRepository.cs
└── UserRepository.cs
├── Startup.cs
├── ViewModel
└── TokenViewModel.cs
├── WeatherForecast.cs
├── appsettings.Development.json
├── appsettings.json
├── bin
└── Debug
│ └── netcoreapp3.1
│ ├── APIFuelStation.deps.json
│ ├── APIFuelStation.dll
│ ├── APIFuelStation.exe
│ ├── APIFuelStation.pdb
│ ├── APIFuelStation.runtimeconfig.dev.json
│ ├── APIFuelStation.runtimeconfig.json
│ ├── APIFuelStation.xml
│ ├── AutoMapper.Extensions.Microsoft.DependencyInjection.dll
│ ├── AutoMapper.dll
│ ├── BCrypt.Net-Next.dll
│ ├── FluentValidation.AspNetCore.dll
│ ├── FluentValidation.DependencyInjectionExtensions.dll
│ ├── FluentValidation.dll
│ ├── MediatR.Extensions.Microsoft.DependencyInjection.dll
│ ├── MediatR.dll
│ ├── Microsoft.AspNetCore.Authentication.JwtBearer.dll
│ ├── Microsoft.AspNetCore.JsonPatch.dll
│ ├── Microsoft.AspNetCore.Mvc.NewtonsoftJson.dll
│ ├── Microsoft.Bcl.AsyncInterfaces.dll
│ ├── Microsoft.Bcl.HashCode.dll
│ ├── Microsoft.Data.SqlClient.dll
│ ├── Microsoft.EntityFrameworkCore.Abstractions.dll
│ ├── Microsoft.EntityFrameworkCore.Design.dll
│ ├── Microsoft.EntityFrameworkCore.Relational.dll
│ ├── Microsoft.EntityFrameworkCore.SqlServer.dll
│ ├── Microsoft.EntityFrameworkCore.dll
│ ├── Microsoft.Extensions.Caching.Abstractions.dll
│ ├── Microsoft.Extensions.Caching.Memory.dll
│ ├── Microsoft.Extensions.Configuration.Abstractions.dll
│ ├── Microsoft.Extensions.Configuration.Binder.dll
│ ├── Microsoft.Extensions.Configuration.dll
│ ├── Microsoft.Extensions.DependencyInjection.Abstractions.dll
│ ├── Microsoft.Extensions.DependencyInjection.dll
│ ├── Microsoft.Extensions.Logging.Abstractions.dll
│ ├── Microsoft.Extensions.Logging.dll
│ ├── Microsoft.Extensions.Options.dll
│ ├── Microsoft.Extensions.Primitives.dll
│ ├── Microsoft.Identity.Client.dll
│ ├── Microsoft.IdentityModel.JsonWebTokens.dll
│ ├── Microsoft.IdentityModel.Logging.dll
│ ├── Microsoft.IdentityModel.Protocols.OpenIdConnect.dll
│ ├── Microsoft.IdentityModel.Protocols.dll
│ ├── Microsoft.IdentityModel.Tokens.dll
│ ├── Microsoft.OpenApi.dll
│ ├── Newtonsoft.Json.Bson.dll
│ ├── Newtonsoft.Json.dll
│ ├── Properties
│ └── launchSettings.json
│ ├── Swashbuckle.AspNetCore.Swagger.dll
│ ├── Swashbuckle.AspNetCore.SwaggerGen.dll
│ ├── Swashbuckle.AspNetCore.SwaggerUI.dll
│ ├── System.Collections.Immutable.dll
│ ├── System.Configuration.ConfigurationManager.dll
│ ├── System.Diagnostics.DiagnosticSource.dll
│ ├── System.IdentityModel.Tokens.Jwt.dll
│ ├── System.Runtime.Caching.dll
│ ├── System.Security.Cryptography.ProtectedData.dll
│ ├── appsettings.Development.json
│ ├── appsettings.json
│ └── runtimes
│ ├── unix
│ └── lib
│ │ ├── netcoreapp2.0
│ │ └── System.Runtime.Caching.dll
│ │ └── netcoreapp2.1
│ │ └── Microsoft.Data.SqlClient.dll
│ ├── win-arm64
│ └── native
│ │ └── sni.dll
│ ├── win-x64
│ └── native
│ │ └── sni.dll
│ ├── win-x86
│ └── native
│ │ └── sni.dll
│ └── win
│ └── lib
│ ├── netcoreapp2.0
│ └── System.Runtime.Caching.dll
│ ├── netcoreapp2.1
│ └── Microsoft.Data.SqlClient.dll
│ └── netstandard2.0
│ └── System.Security.Cryptography.ProtectedData.dll
└── obj
├── APIFuelStation.csproj.EntityFrameworkCore.targets
├── APIFuelStation.csproj.nuget.dgspec.json
├── APIFuelStation.csproj.nuget.g.props
├── APIFuelStation.csproj.nuget.g.targets
├── Debug
└── netcoreapp3.1
│ ├── .NETCoreApp,Version=v3.1.AssemblyAttributes.cs
│ ├── APIFuelStation.AssemblyInfo.cs
│ ├── APIFuelStation.AssemblyInfoInputs.cache
│ ├── APIFuelStation.MvcApplicationPartsAssemblyInfo.cache
│ ├── APIFuelStation.MvcApplicationPartsAssemblyInfo.cs
│ ├── APIFuelStation.RazorTargetAssemblyInfo.cache
│ ├── APIFuelStation.assets.cache
│ ├── APIFuelStation.csproj.CopyComplete
│ ├── APIFuelStation.csproj.CoreCompileInputs.cache
│ ├── APIFuelStation.csproj.FileListAbsolute.txt
│ ├── APIFuelStation.csprojAssemblyReference.cache
│ ├── APIFuelStation.dll
│ ├── APIFuelStation.exe
│ ├── APIFuelStation.genruntimeconfig.cache
│ ├── APIFuelStation.pdb
│ ├── APIFuelStation.xml
│ ├── project.razor.json
│ └── staticwebassets
│ ├── APIFuelStation.StaticWebAssets.Manifest.cache
│ └── APIFuelStation.StaticWebAssets.xml
├── project.assets.json
└── project.nuget.cache
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 |
8 | {
9 | "name": ".NET Core Launch (web)",
10 | "type": "coreclr",
11 | "request": "launch",
12 | "preLaunchTask": "build",
13 | "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/APIFuelStation.dll",
14 | "args": [],
15 | "cwd": "${workspaceFolder}",
16 | "stopAtEntry": false,
17 | "serverReadyAction": {
18 | "action": "openExternally",
19 | "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
20 | },
21 | "env": {
22 | "ASPNETCORE_ENVIRONMENT": "Development"
23 | },
24 | "sourceFileMap": {
25 | "/Views": "${workspaceFolder}/Views"
26 | }
27 | },
28 | {
29 | "name": ".NET Core Attach",
30 | "type": "coreclr",
31 | "request": "attach",
32 | "processId": "${command:pickProcess}"
33 | }
34 | ]
35 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/APIFuelStation.csproj",
11 | "/property:GenerateFullPaths=true",
12 | "/consoleloggerparameters:NoSummary"
13 | ],
14 | "problemMatcher": "$msCompile"
15 | },
16 | {
17 | "label": "publish",
18 | "command": "dotnet",
19 | "type": "process",
20 | "args": [
21 | "publish",
22 | "${workspaceFolder}/APIFuelStation.csproj",
23 | "/property:GenerateFullPaths=true",
24 | "/consoleloggerparameters:NoSummary"
25 | ],
26 | "problemMatcher": "$msCompile"
27 | },
28 | {
29 | "label": "watch",
30 | "command": "dotnet",
31 | "type": "process",
32 | "args": [
33 | "watch",
34 | "run",
35 | "${workspaceFolder}/APIFuelStation.csproj",
36 | "/property:GenerateFullPaths=true",
37 | "/consoleloggerparameters:NoSummary"
38 | ],
39 | "problemMatcher": "$msCompile"
40 | }
41 | ]
42 | }
--------------------------------------------------------------------------------
/APIFuelStation.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 | true
7 | $(NoWarn);1591
8 | enable
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | runtime; build; native; contentfiles; analyzers; buildtransitive
23 | all
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Auth/AuthCommandHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IdentityModel.Tokens.Jwt;
3 | using System.Security.Claims;
4 | using System.Text;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 | using APIFuelStation.CommandBus.Commands;
8 | using APIFuelStation.IRepositories;
9 | using APIFuelStation.Models;
10 | using APIFuelStation.ViewModel;
11 | using MediatR;
12 | using Microsoft.Extensions.Configuration;
13 | using Microsoft.IdentityModel.Tokens;
14 |
15 | namespace APIFuelStation.CommandBus {
16 | public class AuthCommandHandler : IRequestHandler {
17 |
18 | private readonly IUserRepository _userrepository;
19 | private readonly IConfiguration _configuration;
20 |
21 | public AuthCommandHandler (IUserRepository userrepository, IConfiguration configuration) {
22 | this._userrepository = userrepository;
23 | this._configuration = configuration;
24 | }
25 | public async Task Handle (UserAuthCommand request, CancellationToken cancellationToken) {
26 | var user = _userrepository.GetUserByEmail (request.Email);
27 | var userByUserName = _userrepository.GetUserByUserName (request.Email);
28 | var userByPhoneNo = _userrepository.GetUserByPhoneNo (request.Email);
29 |
30 | if (user != null) {
31 | return GetTokenView (user, request);
32 | } else if (userByUserName != null) {
33 | return GetTokenView (userByUserName, request);
34 | } else if (userByPhoneNo != null) {
35 | return GetTokenView (userByPhoneNo, request);
36 | }
37 |
38 | return new TokenViewModel { Token = null, User = null };
39 | }
40 |
41 | public TokenViewModel GetTokenView (User user, UserAuthCommand request) {
42 | if (user != null) {
43 | if (BCrypt.Net.BCrypt.Verify (request.Password, user.Password)) {
44 | var tokenStr = GenerateJSONWebToken (user);
45 | var response = new { token = tokenStr, user = user };
46 | return new TokenViewModel { Token = response.token, User = user };
47 | }
48 | }
49 | return new TokenViewModel { Token = null, User = null };
50 | }
51 |
52 | public string GenerateJSONWebToken (User user) {
53 | var securityKey = new SymmetricSecurityKey (Encoding.UTF8.GetBytes (_configuration["Jwt:Key"]));
54 | var credentials = new SigningCredentials (securityKey, SecurityAlgorithms.HmacSha256);
55 |
56 | var claims = new [] {
57 | new Claim (JwtRegisteredClaimNames.Sub, user.UserName),
58 | new Claim (JwtRegisteredClaimNames.Email, user.Email),
59 | new Claim (JwtRegisteredClaimNames.Jti, Guid.NewGuid ().ToString ())
60 | };
61 |
62 | var token = new JwtSecurityToken (
63 | issuer: _configuration["Jwt:Issuer"],
64 | audience : _configuration["Jwt:Issuer"],
65 | claims,
66 | expires : DateTime.Now.AddMinutes (120),
67 | signingCredentials : credentials
68 | );
69 |
70 | var encodenToken = new JwtSecurityTokenHandler ().WriteToken (token);
71 | return encodenToken;
72 | }
73 | }
74 |
75 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Auth/UserRegisterCommandHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.IRepositories;
4 | using APIFuelStation.Models;
5 | using MediatR;
6 |
7 | namespace APIFuelStation.CommandBus {
8 |
9 | public class UserRegisterCommandHandler : IRequestHandler {
10 | private readonly IUserRepository _userRepository;
11 | public UserRegisterCommandHandler (IUserRepository userRepository) {
12 | this._userRepository = userRepository;
13 | }
14 |
15 | public async Task Handle (UserRegisterCommand request, CancellationToken cancellationToken) {
16 | return await _userRepository.CreateUser (request.User);
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Department/CreateDepartmentHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus
9 | {
10 |
11 | public class CreateDepartmentHandler : IRequestHandler
12 | {
13 | private readonly IDepartmentRepository _departmentRepository;
14 | public CreateDepartmentHandler(IDepartmentRepository departmentRepository)
15 | {
16 | this._departmentRepository = departmentRepository;
17 | }
18 |
19 | public async Task Handle(CreateDepartmentCommand request, CancellationToken cancellationToken)
20 | {
21 | return await _departmentRepository.CreateDepartment(request.Department);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Department/DeleteDepartmentHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus
9 | {
10 |
11 | public class DeleteDepartmentHandler : IRequestHandler
12 | {
13 | private readonly IDepartmentRepository _departmentRepository;
14 | public DeleteDepartmentHandler(IDepartmentRepository departmentRepository)
15 | {
16 | this._departmentRepository = departmentRepository;
17 | }
18 |
19 | public async Task Handle(DeleteDepartmentCommand request, CancellationToken cancellationToken)
20 | {
21 | return await _departmentRepository.DeleteDepartment(request.Department);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Department/UpdateDepartmentHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus
9 | {
10 |
11 | public class UpdateDepartmentHandler : IRequestHandler
12 | {
13 | private readonly IDepartmentRepository _departmentRepository;
14 | public UpdateDepartmentHandler(IDepartmentRepository departmentRepository)
15 | {
16 | this._departmentRepository = departmentRepository;
17 | }
18 |
19 | public async Task Handle(UpdateDepartmentCommand request, CancellationToken cancellationToken)
20 | {
21 | return await _departmentRepository.UpdateDepartment(request.Department);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Designation/CreateDesignationHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus
9 | {
10 |
11 | public class CreateDesignationHandler : IRequestHandler
12 | {
13 | private readonly IDesignationRepository _designationRepository;
14 | public CreateDesignationHandler(IDesignationRepository designationRepository)
15 | {
16 | this._designationRepository = designationRepository;
17 | }
18 |
19 | public async Task Handle(CreateDesignationCommand request, CancellationToken cancellationToken)
20 | {
21 | return await _designationRepository.CreateDesignation(request.Designation);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Designation/DeleteDesignationHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus
9 | {
10 |
11 | public class DeleteDesignationHandler : IRequestHandler
12 | {
13 | private readonly IDesignationRepository _designationRepository;
14 | public DeleteDesignationHandler(IDesignationRepository designationRepository)
15 | {
16 | this._designationRepository = designationRepository;
17 | }
18 |
19 | public async Task Handle(DeleteDesignationCommand request, CancellationToken cancellationToken)
20 | {
21 | return await _designationRepository.DeleteDesignation(request.Designation);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Designation/UpdateDesignationHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus
9 | {
10 |
11 | public class UpdateDesignationHandler : IRequestHandler
12 | {
13 | private readonly IDesignationRepository _designationRepository;
14 | public UpdateDesignationHandler(IDesignationRepository designationRepository)
15 | {
16 | this._designationRepository = designationRepository;
17 | }
18 |
19 | public async Task Handle(UpdateDesignationCommand request, CancellationToken cancellationToken)
20 | {
21 | return await _designationRepository.UpdateDesignation(request.Designation);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Employee/CreateEmployeeHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus {
9 |
10 | public class CreateEmployeeHandler : IRequestHandler {
11 | private readonly IEmployeeRepository _employeeRepository;
12 | public CreateEmployeeHandler (IEmployeeRepository employeeRepository) {
13 | this._employeeRepository = employeeRepository;
14 | }
15 |
16 | public async Task Handle (CreateEmployeeCommand request, CancellationToken cancellationToken) {
17 | return await _employeeRepository.CreateEmployee (request.Employee);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Employee/DeleteEmployeeHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus {
9 |
10 | public class DeleteEmployeeHandler : IRequestHandler {
11 | private readonly IEmployeeRepository _employeeRepository;
12 | public DeleteEmployeeHandler (IEmployeeRepository employeeRepository) {
13 | this._employeeRepository = employeeRepository;
14 | }
15 |
16 | public async Task Handle (DeleteEmployeeCommand request, CancellationToken cancellationToken) {
17 | return await _employeeRepository.DeleteEmployee (request.Employee);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/Employee/UpdateEmployeeHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus {
9 |
10 | public class UpdateEmployeeHandler : IRequestHandler {
11 | private readonly IEmployeeRepository _employeeRepository;
12 | public UpdateEmployeeHandler (IEmployeeRepository employeeRepository) {
13 | this._employeeRepository = employeeRepository;
14 | }
15 |
16 | public async Task Handle (UpdateEmployeeCommand request, CancellationToken cancellationToken) {
17 | return await _employeeRepository.UpdateEmployee (request.Employee);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/User/CreateUserHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus {
9 |
10 | public class CreateUserHandler : IRequestHandler {
11 | private readonly IUserRepository _userRepository;
12 | public CreateUserHandler (IUserRepository userRepository) {
13 | this._userRepository = userRepository;
14 | }
15 |
16 | public async Task Handle (CreateUserCommand request, CancellationToken cancellationToken) {
17 | return await _userRepository.CreateUser (request.User);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/User/DeleteUserHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus {
9 |
10 | public class DeleteUserHandler : IRequestHandler {
11 | private readonly IUserRepository _userRepository;
12 | public DeleteUserHandler (IUserRepository userRepository) {
13 | this._userRepository = userRepository;
14 | }
15 |
16 | public async Task Handle (DeleteUserCommand request, CancellationToken cancellationToken) {
17 | return await _userRepository.DeleteUser (request.User);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/CommandBus/CommandHandlers/User/UpdateUserHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus.Commands;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using MediatR;
7 |
8 | namespace APIFuelStation.CommandBus {
9 |
10 | public class UpdateUserHandler : IRequestHandler {
11 | private readonly IUserRepository _userRepository;
12 | public UpdateUserHandler (IUserRepository userRepository) {
13 | this._userRepository = userRepository;
14 | }
15 |
16 | public async Task Handle (UpdateUserCommand request, CancellationToken cancellationToken) {
17 | return await _userRepository.UpdateUser (request.User);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Auth/UserAuthCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.ViewModel;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands {
5 | public class UserAuthCommand : IRequest {
6 | public string Email { get; set; }
7 | public string Password { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Auth/UserRegisterCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using APIFuelStation.ViewModel;
3 | using MediatR;
4 |
5 | namespace APIFuelStation.CommandBus {
6 | public class UserRegisterCommand : IRequest {
7 | public User User { get; }
8 |
9 | public UserRegisterCommand (User user) {
10 | User = user;
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Department/CreateDepartmentCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands
5 | {
6 | public class CreateDepartmentCommand : IRequest
7 | {
8 | public CreateDepartmentCommand(Department department)
9 | {
10 | Department = department;
11 | }
12 | public Department Department { get; }
13 | }
14 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Department/DeleteDepartmentCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands
5 | {
6 | public class DeleteDepartmentCommand : IRequest
7 | {
8 | public DeleteDepartmentCommand(Department department)
9 | {
10 | Department = department;
11 | }
12 | public Department Department { get; }
13 | }
14 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Department/UpdateDepartmentCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands
5 | {
6 | public class UpdateDepartmentCommand : IRequest
7 | {
8 | public UpdateDepartmentCommand(Department department)
9 | {
10 | Department = department;
11 | }
12 | public Department Department { get; }
13 | }
14 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Designation/CreateDesignationCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands
5 | {
6 | public class CreateDesignationCommand : IRequest
7 | {
8 | public CreateDesignationCommand(Designation designation)
9 | {
10 | Designation = designation;
11 | }
12 | public Designation Designation { get; }
13 | }
14 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Designation/DeleteDesignationCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands
5 | {
6 | public class DeleteDesignationCommand : IRequest
7 | {
8 | public DeleteDesignationCommand(Designation designation)
9 | {
10 | Designation = designation;
11 | }
12 | public Designation Designation { get; }
13 | }
14 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Designation/UpdateDesignationCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands
5 | {
6 | public class UpdateDesignationCommand : IRequest
7 | {
8 | public UpdateDesignationCommand(Designation designation)
9 | {
10 | Designation = designation;
11 | }
12 | public Designation Designation { get; }
13 | }
14 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Employee/CreateEmployeeCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands {
5 | public class CreateEmployeeCommand : IRequest {
6 | public CreateEmployeeCommand (Employee employee) {
7 | Employee = employee;
8 | }
9 | public Employee Employee { get; }
10 | }
11 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Employee/DeleteEmployeeCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands {
5 | public class DeleteEmployeeCommand : IRequest {
6 | public DeleteEmployeeCommand (Employee employee) {
7 | Employee = employee;
8 | }
9 | public Employee Employee { get; }
10 | }
11 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/Employee/UpdateEmployeeCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands {
5 | public class UpdateEmployeeCommand : IRequest {
6 | public UpdateEmployeeCommand (Employee employee) {
7 | Employee = employee;
8 | }
9 | public Employee Employee { get; }
10 | }
11 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/User/CreateUserCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands {
5 | public class CreateUserCommand : IRequest {
6 | public CreateUserCommand (User user) {
7 | User = user;
8 | }
9 | public User User { get; }
10 | }
11 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/User/DeleteUserCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands {
5 | public class DeleteUserCommand : IRequest {
6 | public DeleteUserCommand (User user) {
7 | User = user;
8 | }
9 | public User User { get; }
10 | }
11 | }
--------------------------------------------------------------------------------
/CommandBus/Commands/User/UpdateUserCommand.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using MediatR;
3 |
4 | namespace APIFuelStation.CommandBus.Commands {
5 | public class UpdateUserCommand : IRequest {
6 | public UpdateUserCommand (User user) {
7 | User = user;
8 | }
9 | public User User { get; }
10 | }
11 | }
--------------------------------------------------------------------------------
/Controllers/AuthController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IdentityModel.Tokens.Jwt;
4 | using System.Linq;
5 | using System.Security.Claims;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using APIFuelStation.CommandBus;
9 | using APIFuelStation.CommandBus.Commands;
10 | using APIFuelStation.Models;
11 | using AutoMapper;
12 | using MediatR;
13 | using Microsoft.AspNetCore.Authorization;
14 | using Microsoft.AspNetCore.JsonPatch;
15 | using Microsoft.AspNetCore.Mvc;
16 | using Microsoft.Extensions.Configuration;
17 | using Microsoft.IdentityModel.Tokens;
18 |
19 | namespace APIFuelStation.Controllers {
20 | [ApiController]
21 | [Route ("[controller]")]
22 | public class AuthController : ControllerBase {
23 |
24 | private readonly IConfiguration _configuration;
25 | private readonly IMediator _mediator;
26 | public AuthController (IConfiguration confirugation, IMediator mediator) {
27 | this._configuration = confirugation;
28 | this._mediator = mediator;
29 | }
30 |
31 | [HttpPost ("Login")]
32 | public async Task Login ([FromBody] UserAuthCommand command) {
33 | var result = await _mediator.Send (command);
34 | return Ok (result);
35 | }
36 |
37 | [HttpPost ("Register")]
38 | public async Task Register ([FromBody] UserRegisterCommand command) {
39 | var result = await _mediator.Send (command);
40 | return Ok (result);
41 | }
42 |
43 | }
44 | }
--------------------------------------------------------------------------------
/Controllers/DepartmentsController.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus;
4 | using APIFuelStation.CommandBus.Commands;
5 | using APIFuelStation.Models;
6 | using APIFuelStation.QueryBus;
7 | using APIFuelStation.QueryBus.Queries;
8 | using AutoMapper;
9 | using MediatR;
10 | using Microsoft.AspNetCore.Authorization;
11 | using Microsoft.AspNetCore.JsonPatch;
12 | using Microsoft.AspNetCore.Mvc;
13 |
14 | namespace APIFuelStation.Controllers
15 | {
16 |
17 | [Produces("application/json")]
18 | [Route("/api/[controller]")]
19 | [ApiController]
20 | public class DepartmentsController : ControllerBase
21 | {
22 | private readonly IMediator _mediator;
23 |
24 | public DepartmentsController(IMediator mediator)
25 | {
26 | this._mediator = mediator;
27 | }
28 |
29 | // [Authorize]
30 | ///
31 | /// Get All of the Departments List
32 | ///
33 | /// A New Department
34 | [Authorize]
35 | [HttpGet]
36 | public async Task GetAllDepartments()
37 | {
38 | var allDepartments = await _mediator.Send(new GetAllDepartmentQuery());
39 | return Ok(allDepartments);
40 | }
41 |
42 | // [Authorize]
43 | ///
44 | /// Get Single Department By ID
45 | ///
46 | /// Get an Department
47 | /// If user id not found
48 | [Authorize]
49 | [HttpGet("{id}", Name = "GetDepartmentById")]
50 | public async Task GetDepartmentById(int id)
51 | {
52 | var user = await _mediator.Send(new GetSingleDepartmentQuery(id));
53 | if (user == null)
54 | return NotFound();
55 | return Ok(user);
56 | }
57 |
58 | ///
59 | /// Creates a New Department
60 | ///
61 | ///
62 | /// Sample request:
63 | ///
64 | /// {
65 | /// "id": 0,
66 | /// "name": "Department 1",
67 | /// "code": "DEP12",
68 | /// }
69 | ///
70 | ///
71 | /// A newly created Department Item
72 | /// Returns the newly created item
73 | /// If any of the field is null
74 | [Authorize]
75 | [HttpPost]
76 | public async Task CreateDepartment(Department user)
77 | {
78 | var userResponse = await _mediator.Send(new CreateDepartmentCommand(user));
79 | return Ok(userResponse);
80 | }
81 |
82 | ///
83 | /// Updates a user
84 | ///
85 | ///
86 | /// Sample request:
87 | ///
88 | /// {
89 | /// "id": 0,
90 | /// "firstName": "Maniruzzaman",
91 | /// "lastName": "Akash",
92 | /// "userName": "maniruzzaman",
93 | /// "email": "maniruzzamanAkash@gmail.com",
94 | /// "phoneNo": "01951233084",
95 | /// "password": "123456",
96 | /// "avatar": "string",
97 | /// "gender": true
98 | /// }
99 | ///
100 | ///
101 | /// A newly updated Department Item
102 | /// Returns the newly updated user
103 | /// If any of the field is null
104 | /// If user id not found
105 | [Authorize]
106 | [HttpPut("{id}", Name = "UpdateDepartment")]
107 | public async Task UpdateDepartment(int id, Department user)
108 | {
109 | var departmentSearchByID = await _mediator.Send(new GetSingleDepartmentQuery(id));
110 | if (departmentSearchByID == null)
111 | return NotFound();
112 |
113 | var userResponse = await _mediator.Send(new UpdateDepartmentCommand(user));
114 | return Ok(userResponse);
115 | }
116 |
117 | ///
118 | /// Deletes a user
119 | ///
120 | /// Deleted Department Item
121 | /// Returns the newly deleted user
122 | /// If any of the field is null
123 | /// If user id not found
124 | [Authorize]
125 | [HttpDelete("{id}", Name = "DeleteDepartment")]
126 | public async Task DeleteDepartment(int id)
127 | {
128 | var departmentSearchByID = await _mediator.Send(new GetSingleDepartmentQuery(id));
129 | if (departmentSearchByID == null)
130 | return NotFound();
131 |
132 | var userResponse = await _mediator.Send(new DeleteDepartmentCommand(departmentSearchByID));
133 | return Ok(userResponse);
134 | }
135 | }
136 | }
--------------------------------------------------------------------------------
/Controllers/DesignationsController.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus;
4 | using APIFuelStation.CommandBus.Commands;
5 | using APIFuelStation.Models;
6 | using APIFuelStation.QueryBus;
7 | using APIFuelStation.QueryBus.Queries;
8 | using AutoMapper;
9 | using MediatR;
10 | using Microsoft.AspNetCore.Authorization;
11 | using Microsoft.AspNetCore.JsonPatch;
12 | using Microsoft.AspNetCore.Mvc;
13 |
14 | namespace APIFuelStation.Controllers
15 | {
16 |
17 | [Produces("application/json")]
18 | [Route("/api/[controller]")]
19 | [ApiController]
20 | public class DesignationsController : ControllerBase
21 | {
22 | private readonly IMediator _mediator;
23 |
24 | public DesignationsController(IMediator mediator)
25 | {
26 | this._mediator = mediator;
27 | }
28 |
29 | // [Authorize]
30 | ///
31 | /// Get All of the Designations List
32 | ///
33 | /// A New Designation
34 | [Authorize]
35 | [HttpGet]
36 | public async Task GetAllDesignations()
37 | {
38 | var allDesignations = await _mediator.Send(new GetAllDesignationQuery());
39 | return Ok(allDesignations);
40 | }
41 |
42 | // [Authorize]
43 | ///
44 | /// Get Single Designation By ID
45 | ///
46 | /// Get an Designation
47 | /// If user id not found
48 | [Authorize]
49 | [HttpGet("{id}", Name = "GetDesignationById")]
50 | public async Task GetDesignationById(int id)
51 | {
52 | var user = await _mediator.Send(new GetSingleDesignationQuery(id));
53 | if (user == null)
54 | return NotFound();
55 | return Ok(user);
56 | }
57 |
58 | ///
59 | /// Creates a New Designation
60 | ///
61 | ///
62 | /// Sample request:
63 | ///
64 | /// {
65 | /// "id": 0,
66 | /// "name": "Designation 1",
67 | /// "code": "DEP12",
68 | /// }
69 | ///
70 | ///
71 | /// A newly created Designation Item
72 | /// Returns the newly created item
73 | /// If any of the field is null
74 | [Authorize]
75 | [HttpPost]
76 | public async Task CreateDesignation(Designation user)
77 | {
78 | var userResponse = await _mediator.Send(new CreateDesignationCommand(user));
79 | return Ok(userResponse);
80 | }
81 |
82 | ///
83 | /// Updates a user
84 | ///
85 | ///
86 | /// Sample request:
87 | ///
88 | /// {
89 | /// "id": 0,
90 | /// "firstName": "Maniruzzaman",
91 | /// "lastName": "Akash",
92 | /// "userName": "maniruzzaman",
93 | /// "email": "maniruzzamanAkash@gmail.com",
94 | /// "phoneNo": "01951233084",
95 | /// "password": "123456",
96 | /// "avatar": "string",
97 | /// "gender": true
98 | /// }
99 | ///
100 | ///
101 | /// A newly updated Designation Item
102 | /// Returns the newly updated user
103 | /// If any of the field is null
104 | /// If user id not found
105 | [Authorize]
106 | [HttpPut("{id}", Name = "UpdateDesignation")]
107 | public async Task UpdateDesignation(int id, Designation user)
108 | {
109 | var designationSearchByID = await _mediator.Send(new GetSingleDesignationQuery(id));
110 | if (designationSearchByID == null)
111 | return NotFound();
112 |
113 | var userResponse = await _mediator.Send(new UpdateDesignationCommand(user));
114 | return Ok(userResponse);
115 | }
116 |
117 | ///
118 | /// Deletes a user
119 | ///
120 | /// Deleted Designation Item
121 | /// Returns the newly deleted user
122 | /// If any of the field is null
123 | /// If user id not found
124 | [Authorize]
125 | [HttpDelete("{id}", Name = "DeleteDesignation")]
126 | public async Task DeleteDesignation(int id)
127 | {
128 | var designationSearchByID = await _mediator.Send(new GetSingleDesignationQuery(id));
129 | if (designationSearchByID == null)
130 | return NotFound();
131 |
132 | var userResponse = await _mediator.Send(new DeleteDesignationCommand(designationSearchByID));
133 | return Ok(userResponse);
134 | }
135 | }
136 | }
--------------------------------------------------------------------------------
/Controllers/DummyControllerExample.cs:
--------------------------------------------------------------------------------
1 | namespace APIFuelStation.Controllers {
2 | public class DummyControllerExample {
3 | // private readonly IMediator _mediator;
4 |
5 | // public UsersController (IMediator mediator) {
6 | // this._mediator = mediator;
7 | // }
8 |
9 | // // [Authorize]
10 | // ///
11 | // /// Get All of the Users List
12 | // ///
13 | // /// A New User
14 | // [Authorize]
15 | // [HttpGet]
16 | // public async Task GetAllUsers () {
17 | // var allUsers = await _mediator.Send (new GetAllUserQuery ());
18 | // return Ok (allUsers);
19 | // }
20 |
21 | // // [Authorize]
22 | // ///
23 | // /// Get Single User By ID
24 | // ///
25 | // /// Get an User
26 | // /// If user id not found
27 | // [Authorize]
28 | // [HttpGet ("{id}", Name = "GetUserById")]
29 | // public async Task GetUserById (int id) {
30 | // var user = await _mediator.Send (new GetSingleUserQuery (id));
31 | // if (user == null)
32 | // return NotFound ();
33 | // return Ok (user);
34 | // }
35 |
36 | // ///
37 | // /// Creates a New User
38 | // ///
39 | // ///
40 | // /// Sample request:
41 | // ///
42 | // /// {
43 | // /// "id": 0,
44 | // /// "firstName": "Maniruzzaman",
45 | // /// "lastName": "Akash",
46 | // /// "userName": "maniruzzaman",
47 | // /// "email": "maniruzzamanAkash@gmail.com",
48 | // /// "phoneNo": "01951233084",
49 | // /// "password": "123456",
50 | // /// "avatar": "string",
51 | // /// "gender": true
52 | // /// }
53 | // ///
54 | // ///
55 | // /// A newly created User Item
56 | // /// Returns the newly created item
57 | // /// If any of the field is null
58 | // [Authorize]
59 | // [HttpPost]
60 | // public async Task CreateUser (User user) {
61 | // var userResponse = await _mediator.Send (new CreateUserCommand (user));
62 | // return Ok (userResponse);
63 | // }
64 |
65 | // ///
66 | // /// Updates a user
67 | // ///
68 | // ///
69 | // /// Sample request:
70 | // ///
71 | // /// {
72 | // /// "id": 0,
73 | // /// "firstName": "Maniruzzaman",
74 | // /// "lastName": "Akash",
75 | // /// "userName": "maniruzzaman",
76 | // /// "email": "maniruzzamanAkash@gmail.com",
77 | // /// "phoneNo": "01951233084",
78 | // /// "password": "123456",
79 | // /// "avatar": "string",
80 | // /// "gender": true
81 | // /// }
82 | // ///
83 | // ///
84 | // /// A newly updated User Item
85 | // /// Returns the newly updated user
86 | // /// If any of the field is null
87 | // /// If user id not found
88 | // [Authorize]
89 | // [HttpPut ("{id}", Name = "UpdateUser")]
90 | // public async Task UpdateUser (int id, User user) {
91 | // var userSearchByID = await _mediator.Send (new GetSingleUserQuery (id));
92 | // if (userSearchByID == null)
93 | // return NotFound ();
94 |
95 | // var userResponse = await _mediator.Send (new UpdateUserCommand (user));
96 | // return Ok (userResponse);
97 | // }
98 |
99 | // ///
100 | // /// Deletes a user
101 | // ///
102 | // /// Deleted User Item
103 | // /// Returns the newly deleted user
104 | // /// If any of the field is null
105 | // /// If user id not found
106 | // [Authorize]
107 | // [HttpDelete ("{id}", Name = "DeleteUser")]
108 | // public async Task DeleteUser (int id) {
109 | // var userSearchByID = await _mediator.Send (new GetSingleUserQuery (id));
110 | // if (userSearchByID == null)
111 | // return NotFound ();
112 |
113 | // var userResponse = await _mediator.Send (new DeleteUserCommand (userSearchByID));
114 | // return Ok (userResponse);
115 | // }
116 |
117 | // [Authorize]
118 | // [HttpGet("{id}", Name = "GetCategoryById")]
119 | // public ActionResult GetCategoryById(int id)
120 | // {
121 | // var categoryItem = _repository.GetCategoryById(id);
122 | // if (categoryItem == null)
123 | // return NotFound();
124 | // return Ok(_mapper.Map(categoryItem));
125 | // }
126 |
127 | // [Authorize]
128 | // // POST api/categories
129 | // [HttpPost]
130 | // public ActionResult CreateCategory(CategoryCreateDto categoryCreateDto)
131 | // {
132 | // var categoryModel = _mapper.Map(categoryCreateDto);
133 | // _repository.CreateCategory(categoryModel);
134 | // _repository.SaveChanges();
135 |
136 | // var categoryReadDto = _mapper.Map(categoryModel);
137 |
138 | // return CreatedAtRoute(nameof(GetCategoryById), new { Id = categoryReadDto.Id }, categoryReadDto);
139 |
140 | // //return Ok(commandReadDto);
141 | // }
142 |
143 | // [Authorize]
144 | // POST api/categories
145 | // [HttpPost]
146 | // public async Task CreateCategory([FromBody] CreateCategoryOrderRequest request)
147 | // {
148 | // var categoryModel = _mapper.Map(categoryCreateDto);
149 | // _repository.CreateCategory(categoryModel);
150 | // _repository.SaveChanges();
151 |
152 | // var categoryReadDto = _mapper.Map(categoryModel);
153 |
154 | // return CreatedAtRoute(nameof(GetCategoryById), new { Id = categoryReadDto.Id }, categoryReadDto);
155 |
156 | // //return Ok(commandReadDto);
157 | // }
158 |
159 | // [Authorize]
160 | // // PUT api/categories
161 | // [HttpPut("{id}")]
162 | // public ActionResult UpdateCategory(int id, CategoryCreateDto CategoryUpdateDto)
163 | // {
164 | // var categorydModelFromRepo = _repository.GetCategoryById(id);
165 | // if (categorydModelFromRepo == null)
166 | // {
167 | // return NotFound();
168 | // }
169 |
170 | // _mapper.Map(CategoryUpdateDto, categorydModelFromRepo);
171 |
172 | // _repository.UpdateCategory(categorydModelFromRepo);
173 |
174 | // _repository.SaveChanges();
175 |
176 | // var categoryReadItem = _repository.GetCategoryById(id);
177 | // if (categoryReadItem == null)
178 | // return NoContent();
179 | // return Ok(_mapper.Map(categoryReadItem));
180 | // }
181 |
182 | // [Authorize]
183 | // // PATCH api/categories
184 | // [HttpPatch("{id}")]
185 | // public ActionResult PartialUpdateCategory(int id, JsonPatchDocument patchDoc)
186 | // {
187 | // var categoryModelFromRepo = _repository.GetCategoryById(id);
188 | // if (categoryModelFromRepo == null)
189 | // {
190 | // return NotFound();
191 | // }
192 |
193 | // var categoryToPatch = _mapper.Map(categoryModelFromRepo);
194 | // patchDoc.ApplyTo(categoryToPatch, ModelState);
195 |
196 | // if (!TryValidateModel(categoryToPatch))
197 | // {
198 | // return ValidationProblem(ModelState);
199 | // }
200 |
201 | // _mapper.Map(categoryToPatch, categoryModelFromRepo);
202 | // _repository.UpdateCategory(categoryModelFromRepo);
203 | // _repository.SaveChanges();
204 |
205 | // var categoryReadItem = _repository.GetCategoryById(id);
206 | // if (categoryReadItem == null)
207 | // return NoContent();
208 | // return Ok(_mapper.Map(categoryReadItem));
209 | // }
210 |
211 | // [Authorize]
212 | // // DELeTE api/categories
213 | // [HttpDelete("{id}")]
214 | // public ActionResult DeleteCategory(int id)
215 | // {
216 | // var categoryModelFromRepo = _repository.GetCategoryById(id);
217 | // if (categoryModelFromRepo == null)
218 | // {
219 | // return NotFound();
220 | // }
221 |
222 | // _repository.DeleteCategory(categoryModelFromRepo);
223 | // _repository.SaveChanges();
224 |
225 | // return NoContent();
226 | // }
227 | }
228 | }
--------------------------------------------------------------------------------
/Controllers/EmployeesController.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus;
4 | using APIFuelStation.CommandBus.Commands;
5 | using APIFuelStation.Models;
6 | using APIFuelStation.QueryBus.Queries;
7 | using AutoMapper;
8 | using MediatR;
9 | using Microsoft.AspNetCore.Authorization;
10 | using Microsoft.AspNetCore.JsonPatch;
11 | using Microsoft.AspNetCore.Mvc;
12 |
13 | namespace APIFuelStation.Controllers {
14 |
15 | [Produces ("application/json")]
16 | [Route ("/api/[controller]")]
17 | [ApiController]
18 | public class EmployeesController : ControllerBase {
19 | private readonly IMediator _mediator;
20 |
21 | public EmployeesController (IMediator mediator) {
22 | this._mediator = mediator;
23 | }
24 |
25 | // [Authorize]
26 | ///
27 | /// Get All of the Employees List
28 | ///
29 | /// A New Employee
30 | [Authorize]
31 | [HttpGet]
32 | public async Task GetAllEmployees () {
33 | var allEmployees = await _mediator.Send (new GetAllEmployeeQuery ());
34 | return Ok (allEmployees);
35 | }
36 |
37 | // [Authorize]
38 | ///
39 | /// Get Single Employee By ID
40 | ///
41 | /// Get an Employee
42 | /// If user id not found
43 | [Authorize]
44 | [HttpGet ("{id}", Name = "GetEmployeeById")]
45 | public async Task GetEmployeeById (int id) {
46 | var user = await _mediator.Send (new GetSingleEmployeeQuery (id));
47 | if (user == null)
48 | return NotFound ();
49 | return Ok (user);
50 | }
51 |
52 | ///
53 | /// Creates a New Employee
54 | ///
55 | ///
56 | /// Sample request:
57 | ///
58 | /// {
59 | /// "id": 0,
60 | /// "firstName": "string",
61 | /// "userName": "string",
62 | /// "email": "string",
63 | /// "phoneNo": "string",
64 | /// "gender": true,
65 | /// "lastName": "string",
66 | /// "password": "string",
67 | /// "avatar": "string",
68 | /// "joiningDate": "2020-06-23",
69 | /// "designationId": 0,
70 | /// "departmentId": 0
71 | /// }
72 | ///
73 | ///
74 | /// A newly created Employee Item
75 | /// Returns the newly created item
76 | /// If any of the field is null
77 | [Authorize]
78 | [HttpPost]
79 | public async Task CreateEmployee (Employee user) {
80 | var userResponse = await _mediator.Send (new CreateEmployeeCommand (user));
81 | return Ok (userResponse);
82 | }
83 |
84 | ///
85 | /// Updates an employee
86 | ///
87 | ///
88 | /// Sample request:
89 | ///
90 | /// {
91 | /// "id": 1,
92 | /// "firstName": "string",
93 | /// "userName": "string",
94 | /// "email": "string",
95 | /// "phoneNo": "string",
96 | /// "gender": true,
97 | /// "lastName": "string",
98 | /// "password": "string",
99 | /// "avatar": "string",
100 | /// "joiningDate": "2020-06-23",
101 | /// "designationId": 0,
102 | /// "departmentId": 0
103 | /// }
104 | ///
105 | ///
106 | /// A newly updated Employee Item
107 | /// Returns the newly updated user
108 | /// If any of the field is null
109 | /// If user id not found
110 | [Authorize]
111 | [HttpPut ("{id}", Name = "UpdateEmployee")]
112 | public async Task UpdateEmployee (int id, Employee user) {
113 | var userSearchByID = await _mediator.Send (new GetSingleEmployeeQuery (id));
114 | if (userSearchByID == null)
115 | return NotFound ();
116 |
117 | var userResponse = await _mediator.Send (new UpdateEmployeeCommand (user));
118 | return Ok (userResponse);
119 | }
120 |
121 | ///
122 | /// Deletes a user
123 | ///
124 | /// Deleted Employee Item
125 | /// Returns the newly deleted user
126 | /// If any of the field is null
127 | /// If user id not found
128 | [Authorize]
129 | [HttpDelete ("{id}", Name = "DeleteEmployee")]
130 | public async Task DeleteEmployee (int id) {
131 | var userSearchByID = await _mediator.Send (new GetSingleEmployeeQuery (id));
132 | if (userSearchByID == null)
133 | return NotFound ();
134 |
135 | var userResponse = await _mediator.Send (new DeleteEmployeeCommand (userSearchByID));
136 | return Ok (userResponse);
137 | }
138 | }
139 | }
--------------------------------------------------------------------------------
/Controllers/UsersController.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.CommandBus;
4 | using APIFuelStation.CommandBus.Commands;
5 | using APIFuelStation.Models;
6 | using APIFuelStation.QueryBus.Queries;
7 | using AutoMapper;
8 | using MediatR;
9 | using Microsoft.AspNetCore.Authorization;
10 | using Microsoft.AspNetCore.JsonPatch;
11 | using Microsoft.AspNetCore.Mvc;
12 |
13 | namespace APIFuelStation.Controllers {
14 |
15 | [Produces ("application/json")]
16 | [Route ("/api/[controller]")]
17 | [ApiController]
18 | public class UsersController : ControllerBase {
19 | private readonly IMediator _mediator;
20 |
21 | public UsersController (IMediator mediator) {
22 | this._mediator = mediator;
23 | }
24 |
25 | // [Authorize]
26 | ///
27 | /// Get All of the Users List
28 | ///
29 | /// A New User
30 | [Authorize]
31 | [HttpGet]
32 | public async Task GetAllUsers () {
33 | var allUsers = await _mediator.Send (new GetAllUserQuery ());
34 | return Ok (allUsers);
35 | }
36 |
37 | // [Authorize]
38 | ///
39 | /// Get Single User By ID
40 | ///
41 | /// Get an User
42 | /// If user id not found
43 | [Authorize]
44 | [HttpGet ("{id}", Name = "GetUserById")]
45 | public async Task GetUserById (int id) {
46 | var user = await _mediator.Send (new GetSingleUserQuery (id));
47 | if (user == null)
48 | return NotFound ();
49 | return Ok (user);
50 | }
51 |
52 | ///
53 | /// Creates a New User
54 | ///
55 | ///
56 | /// Sample request:
57 | ///
58 | /// {
59 | /// "id": 0,
60 | /// "firstName": "Maniruzzaman",
61 | /// "lastName": "Akash",
62 | /// "userName": "maniruzzaman",
63 | /// "email": "maniruzzamanAkash@gmail.com",
64 | /// "phoneNo": "01951233084",
65 | /// "password": "123456",
66 | /// "avatar": "string",
67 | /// "gender": true
68 | /// }
69 | ///
70 | ///
71 | /// A newly created User Item
72 | /// Returns the newly created item
73 | /// If any of the field is null
74 | [Authorize]
75 | [HttpPost]
76 | public async Task CreateUser (User user) {
77 | var userResponse = await _mediator.Send (new CreateUserCommand (user));
78 | return Ok (userResponse);
79 | }
80 |
81 | ///
82 | /// Updates a user
83 | ///
84 | ///
85 | /// Sample request:
86 | ///
87 | /// {
88 | /// "id": 0,
89 | /// "firstName": "Maniruzzaman",
90 | /// "lastName": "Akash",
91 | /// "userName": "maniruzzaman",
92 | /// "email": "maniruzzamanAkash@gmail.com",
93 | /// "phoneNo": "01951233084",
94 | /// "password": "123456",
95 | /// "avatar": "string",
96 | /// "gender": true
97 | /// }
98 | ///
99 | ///
100 | /// A newly updated User Item
101 | /// Returns the newly updated user
102 | /// If any of the field is null
103 | /// If user id not found
104 | [Authorize]
105 | [HttpPut ("{id}", Name = "UpdateUser")]
106 | public async Task UpdateUser (int id, User user) {
107 | var userSearchByID = await _mediator.Send (new GetSingleUserQuery (id));
108 | if (userSearchByID == null)
109 | return NotFound ();
110 |
111 | var userResponse = await _mediator.Send (new UpdateUserCommand (user));
112 | return Ok (userResponse);
113 | }
114 |
115 | ///
116 | /// Deletes a user
117 | ///
118 | /// Deleted User Item
119 | /// Returns the newly deleted user
120 | /// If any of the field is null
121 | /// If user id not found
122 | [Authorize]
123 | [HttpDelete ("{id}", Name = "DeleteUser")]
124 | public async Task DeleteUser (int id) {
125 | var userSearchByID = await _mediator.Send (new GetSingleUserQuery (id));
126 | if (userSearchByID == null)
127 | return NotFound ();
128 |
129 | var userResponse = await _mediator.Send (new DeleteUserCommand (userSearchByID));
130 | return Ok (userResponse);
131 | }
132 | }
133 | }
--------------------------------------------------------------------------------
/Controllers/WeatherForecastController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Mvc;
6 | using Microsoft.Extensions.Logging;
7 |
8 | namespace APIFuelStation.Controllers
9 | {
10 | [ApiController]
11 | [Route("[controller]")]
12 | public class WeatherForecastController : ControllerBase
13 | {
14 | private static readonly string[] Summaries = new[]
15 | {
16 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
17 | };
18 |
19 | private readonly ILogger _logger;
20 |
21 | public WeatherForecastController(ILogger logger)
22 | {
23 | _logger = logger;
24 | }
25 |
26 | [HttpGet]
27 | public IEnumerable Get()
28 | {
29 | var rng = new Random();
30 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast
31 | {
32 | Date = DateTime.Now.AddDays(index),
33 | TemperatureC = rng.Next(-20, 55),
34 | Summary = Summaries[rng.Next(Summaries.Length)]
35 | })
36 | .ToArray();
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/DbContexts/FuelDBContext.cs:
--------------------------------------------------------------------------------
1 | using APIFuelStation.Models;
2 | using Microsoft.EntityFrameworkCore;
3 |
4 | namespace APIFuelStation.DbContexts {
5 | public class FuelDBContext : DbContext {
6 |
7 | public FuelDBContext (DbContextOptions opt) : base (opt) {
8 |
9 | }
10 |
11 | // public DbSet Commands { get; set; }
12 | public DbSet Users { get; set; }
13 | public DbSet Departments { get; set; }
14 | public DbSet Designations { get; set; }
15 | public DbSet Employees { get; set; }
16 |
17 | // Keys
18 | protected override void OnModelCreating (ModelBuilder modelBuilder) {
19 | // User Model
20 | modelBuilder.Entity ()
21 | .HasIndex (user => user.Email)
22 | .IsUnique ();
23 | modelBuilder.Entity ()
24 | .HasIndex (user => user.PhoneNo)
25 | .IsUnique ();
26 | modelBuilder.Entity ()
27 | .HasIndex (user => user.UserName)
28 | .IsUnique ();
29 |
30 | // Department Model
31 | modelBuilder.Entity ()
32 | .HasIndex (department => department.Code)
33 | .IsUnique ();
34 |
35 | // Designation Model
36 | modelBuilder.Entity ()
37 | .HasIndex (designation => designation.Code)
38 | .IsUnique ();
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/IRepositories/IAuthRepository.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.Models;
4 |
5 | namespace APIFuelStation.IRepositories {
6 | public interface IAuthRepository {
7 | bool SaveChanges ();
8 |
9 | Task Register (User user);
10 | Task Login (User user);
11 | }
12 | }
--------------------------------------------------------------------------------
/IRepositories/IDepartmentRepository.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.Models;
4 |
5 | namespace APIFuelStation.IRepositories
6 | {
7 | public interface IDepartmentRepository
8 | {
9 |
10 | List GetAllDepartments();
11 | Department GetDepartmentById(int id);
12 | Department GetDepartmentByCode(string code);
13 | Task CreateDepartment(Department department);
14 | Task UpdateDepartment(Department department);
15 | Task DeleteDepartment(Department department);
16 |
17 | }
18 | }
--------------------------------------------------------------------------------
/IRepositories/IDesignationRepository.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.Models;
4 |
5 | namespace APIFuelStation.IRepositories
6 | {
7 | public interface IDesignationRepository
8 | {
9 |
10 | List GetAllDesignations();
11 | Designation GetDesignationById(int id);
12 | Designation GetDesignationByCode(string code);
13 | Task CreateDesignation(Designation designation);
14 | Task UpdateDesignation(Designation designation);
15 | Task DeleteDesignation(Designation designation);
16 |
17 | }
18 | }
--------------------------------------------------------------------------------
/IRepositories/IEmployeeRepository.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.Models;
4 |
5 | namespace APIFuelStation.IRepositories {
6 | public interface IEmployeeRepository {
7 |
8 | List GetAllEmployees ();
9 | Employee GetEmployeeById (int id);
10 | Employee GetEmployeeByEmail (string email);
11 | Employee GetEmployeeByEmployeeName (string userName);
12 | Employee GetEmployeeByPhoneNo (string phoneNo);
13 | Task CreateEmployee (Employee user);
14 | Task UpdateEmployee (Employee user);
15 | Task DeleteEmployee (Employee user);
16 |
17 | }
18 | }
--------------------------------------------------------------------------------
/IRepositories/IUserRepository.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using APIFuelStation.Models;
4 |
5 | namespace APIFuelStation.IRepositories {
6 | public interface IUserRepository {
7 |
8 | List GetAllUsers ();
9 | User GetUserById (int id);
10 | User GetUserByEmail (string email);
11 | User GetUserByUserName (string userName);
12 | User GetUserByPhoneNo (string phoneNo);
13 | Task CreateUser (User user);
14 | Task UpdateUser (User user);
15 | Task DeleteUser (User user);
16 |
17 | }
18 | }
--------------------------------------------------------------------------------
/Migrations/20200619131033_UserTableMigration.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using APIFuelStation.DbContexts;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Metadata;
6 | using Microsoft.EntityFrameworkCore.Migrations;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace APIFuelStation.Migrations
10 | {
11 | [DbContext(typeof(FuelDBContext))]
12 | [Migration("20200619131033_UserTableMigration")]
13 | partial class UserTableMigration
14 | {
15 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .HasAnnotation("ProductVersion", "3.1.5")
20 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
21 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
22 |
23 | modelBuilder.Entity("APIFuelStation.Models.User", b =>
24 | {
25 | b.Property("Id")
26 | .ValueGeneratedOnAdd()
27 | .HasColumnType("int")
28 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
29 |
30 | b.Property("Avatar")
31 | .IsRequired()
32 | .HasColumnType("nvarchar(250)")
33 | .HasMaxLength(250);
34 |
35 | b.Property("Email")
36 | .IsRequired()
37 | .HasColumnType("nvarchar(100)")
38 | .HasMaxLength(100);
39 |
40 | b.Property("FirstName")
41 | .IsRequired()
42 | .HasColumnType("nvarchar(50)")
43 | .HasMaxLength(50);
44 |
45 | b.Property("Gender")
46 | .HasColumnType("bit");
47 |
48 | b.Property("LastName")
49 | .IsRequired()
50 | .HasColumnType("nvarchar(30)")
51 | .HasMaxLength(30);
52 |
53 | b.Property("Password")
54 | .IsRequired()
55 | .HasColumnType("nvarchar(100)")
56 | .HasMaxLength(100);
57 |
58 | b.Property("PhoneNo")
59 | .IsRequired()
60 | .HasColumnType("nvarchar(15)")
61 | .HasMaxLength(15);
62 |
63 | b.Property("UserName")
64 | .IsRequired()
65 | .HasColumnType("nvarchar(50)")
66 | .HasMaxLength(50);
67 |
68 | b.HasKey("Id");
69 |
70 | b.ToTable("Users");
71 | });
72 | #pragma warning restore 612, 618
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Migrations/20200619131033_UserTableMigration.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 |
3 | namespace APIFuelStation.Migrations
4 | {
5 | public partial class UserTableMigration : Migration
6 | {
7 | protected override void Up(MigrationBuilder migrationBuilder)
8 | {
9 | migrationBuilder.CreateTable(
10 | name: "Users",
11 | columns: table => new
12 | {
13 | Id = table.Column(nullable: false)
14 | .Annotation("SqlServer:Identity", "1, 1"),
15 | FirstName = table.Column(maxLength: 50, nullable: false),
16 | LastName = table.Column(maxLength: 30, nullable: false),
17 | UserName = table.Column(maxLength: 50, nullable: false),
18 | Email = table.Column(maxLength: 100, nullable: false),
19 | PhoneNo = table.Column(maxLength: 15, nullable: false),
20 | Password = table.Column(maxLength: 100, nullable: false),
21 | Avatar = table.Column(maxLength: 250, nullable: false),
22 | Gender = table.Column(nullable: false)
23 | },
24 | constraints: table =>
25 | {
26 | table.PrimaryKey("PK_Users", x => x.Id);
27 | });
28 | }
29 |
30 | protected override void Down(MigrationBuilder migrationBuilder)
31 | {
32 | migrationBuilder.DropTable(
33 | name: "Users");
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Migrations/20200620044643_UniqueEmail.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using APIFuelStation.DbContexts;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Metadata;
6 | using Microsoft.EntityFrameworkCore.Migrations;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace APIFuelStation.Migrations
10 | {
11 | [DbContext(typeof(FuelDBContext))]
12 | [Migration("20200620044643_UniqueEmail")]
13 | partial class UniqueEmail
14 | {
15 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .HasAnnotation("ProductVersion", "3.1.5")
20 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
21 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
22 |
23 | modelBuilder.Entity("APIFuelStation.Models.User", b =>
24 | {
25 | b.Property("Id")
26 | .ValueGeneratedOnAdd()
27 | .HasColumnType("int")
28 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
29 |
30 | b.Property("Avatar")
31 | .IsRequired()
32 | .HasColumnType("nvarchar(250)")
33 | .HasMaxLength(250);
34 |
35 | b.Property("Email")
36 | .IsRequired()
37 | .HasColumnType("nvarchar(100)")
38 | .HasMaxLength(100);
39 |
40 | b.Property("FirstName")
41 | .IsRequired()
42 | .HasColumnType("nvarchar(50)")
43 | .HasMaxLength(50);
44 |
45 | b.Property("Gender")
46 | .HasColumnType("bit");
47 |
48 | b.Property("LastName")
49 | .IsRequired()
50 | .HasColumnType("nvarchar(30)")
51 | .HasMaxLength(30);
52 |
53 | b.Property("Password")
54 | .IsRequired()
55 | .HasColumnType("nvarchar(100)")
56 | .HasMaxLength(100);
57 |
58 | b.Property("PhoneNo")
59 | .IsRequired()
60 | .HasColumnType("nvarchar(15)")
61 | .HasMaxLength(15);
62 |
63 | b.Property("UserName")
64 | .IsRequired()
65 | .HasColumnType("nvarchar(50)")
66 | .HasMaxLength(50);
67 |
68 | b.HasKey("Id");
69 |
70 | b.HasIndex("Email")
71 | .IsUnique();
72 |
73 | b.ToTable("Users");
74 | });
75 | #pragma warning restore 612, 618
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Migrations/20200620044643_UniqueEmail.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 |
3 | namespace APIFuelStation.Migrations
4 | {
5 | public partial class UniqueEmail : Migration
6 | {
7 | protected override void Up(MigrationBuilder migrationBuilder)
8 | {
9 | migrationBuilder.CreateIndex(
10 | name: "IX_Users_Email",
11 | table: "Users",
12 | column: "Email",
13 | unique: true);
14 | }
15 |
16 | protected override void Down(MigrationBuilder migrationBuilder)
17 | {
18 | migrationBuilder.DropIndex(
19 | name: "IX_Users_Email",
20 | table: "Users");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Migrations/20200620045532_UniquePhoneUsername.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using APIFuelStation.DbContexts;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Metadata;
6 | using Microsoft.EntityFrameworkCore.Migrations;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace APIFuelStation.Migrations
10 | {
11 | [DbContext(typeof(FuelDBContext))]
12 | [Migration("20200620045532_UniquePhoneUsername")]
13 | partial class UniquePhoneUsername
14 | {
15 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .HasAnnotation("ProductVersion", "3.1.5")
20 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
21 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
22 |
23 | modelBuilder.Entity("APIFuelStation.Models.User", b =>
24 | {
25 | b.Property("Id")
26 | .ValueGeneratedOnAdd()
27 | .HasColumnType("int")
28 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
29 |
30 | b.Property("Avatar")
31 | .IsRequired()
32 | .HasColumnType("nvarchar(250)")
33 | .HasMaxLength(250);
34 |
35 | b.Property("Email")
36 | .IsRequired()
37 | .HasColumnType("nvarchar(100)")
38 | .HasMaxLength(100);
39 |
40 | b.Property("FirstName")
41 | .IsRequired()
42 | .HasColumnType("nvarchar(50)")
43 | .HasMaxLength(50);
44 |
45 | b.Property("Gender")
46 | .HasColumnType("bit");
47 |
48 | b.Property("LastName")
49 | .IsRequired()
50 | .HasColumnType("nvarchar(30)")
51 | .HasMaxLength(30);
52 |
53 | b.Property("Password")
54 | .IsRequired()
55 | .HasColumnType("nvarchar(100)")
56 | .HasMaxLength(100);
57 |
58 | b.Property("PhoneNo")
59 | .IsRequired()
60 | .HasColumnType("nvarchar(15)")
61 | .HasMaxLength(15);
62 |
63 | b.Property("UserName")
64 | .IsRequired()
65 | .HasColumnType("nvarchar(50)")
66 | .HasMaxLength(50);
67 |
68 | b.HasKey("Id");
69 |
70 | b.HasIndex("Email")
71 | .IsUnique();
72 |
73 | b.HasIndex("PhoneNo")
74 | .IsUnique();
75 |
76 | b.HasIndex("UserName")
77 | .IsUnique();
78 |
79 | b.ToTable("Users");
80 | });
81 | #pragma warning restore 612, 618
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Migrations/20200620045532_UniquePhoneUsername.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 |
3 | namespace APIFuelStation.Migrations
4 | {
5 | public partial class UniquePhoneUsername : Migration
6 | {
7 | protected override void Up(MigrationBuilder migrationBuilder)
8 | {
9 | migrationBuilder.CreateIndex(
10 | name: "IX_Users_PhoneNo",
11 | table: "Users",
12 | column: "PhoneNo",
13 | unique: true);
14 |
15 | migrationBuilder.CreateIndex(
16 | name: "IX_Users_UserName",
17 | table: "Users",
18 | column: "UserName",
19 | unique: true);
20 | }
21 |
22 | protected override void Down(MigrationBuilder migrationBuilder)
23 | {
24 | migrationBuilder.DropIndex(
25 | name: "IX_Users_PhoneNo",
26 | table: "Users");
27 |
28 | migrationBuilder.DropIndex(
29 | name: "IX_Users_UserName",
30 | table: "Users");
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Migrations/20200620070410_DepartmentDesignationMigration.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using APIFuelStation.DbContexts;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Metadata;
6 | using Microsoft.EntityFrameworkCore.Migrations;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace APIFuelStation.Migrations
10 | {
11 | [DbContext(typeof(FuelDBContext))]
12 | [Migration("20200620070410_DepartmentDesignationMigration")]
13 | partial class DepartmentDesignationMigration
14 | {
15 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .HasAnnotation("ProductVersion", "3.1.5")
20 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
21 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
22 |
23 | modelBuilder.Entity("APIFuelStation.Models.Department", b =>
24 | {
25 | b.Property("Id")
26 | .ValueGeneratedOnAdd()
27 | .HasColumnType("int")
28 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
29 |
30 | b.Property("Code")
31 | .HasColumnType("nvarchar(100)")
32 | .HasMaxLength(100);
33 |
34 | b.Property("Description")
35 | .HasColumnType("nvarchar(max)");
36 |
37 | b.Property("Name")
38 | .IsRequired()
39 | .HasColumnType("nvarchar(100)")
40 | .HasMaxLength(100);
41 |
42 | b.HasKey("Id");
43 |
44 | b.HasIndex("Code")
45 | .IsUnique()
46 | .HasFilter("[Code] IS NOT NULL");
47 |
48 | b.ToTable("Departments");
49 | });
50 |
51 | modelBuilder.Entity("APIFuelStation.Models.Designation", b =>
52 | {
53 | b.Property("Id")
54 | .ValueGeneratedOnAdd()
55 | .HasColumnType("int")
56 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
57 |
58 | b.Property("Code")
59 | .HasColumnType("nvarchar(100)")
60 | .HasMaxLength(100);
61 |
62 | b.Property("Description")
63 | .HasColumnType("nvarchar(max)");
64 |
65 | b.Property("Name")
66 | .IsRequired()
67 | .HasColumnType("nvarchar(100)")
68 | .HasMaxLength(100);
69 |
70 | b.HasKey("Id");
71 |
72 | b.HasIndex("Code")
73 | .IsUnique()
74 | .HasFilter("[Code] IS NOT NULL");
75 |
76 | b.ToTable("Designations");
77 | });
78 |
79 | modelBuilder.Entity("APIFuelStation.Models.User", b =>
80 | {
81 | b.Property("Id")
82 | .ValueGeneratedOnAdd()
83 | .HasColumnType("int")
84 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
85 |
86 | b.Property("Avatar")
87 | .IsRequired()
88 | .HasColumnType("nvarchar(250)")
89 | .HasMaxLength(250);
90 |
91 | b.Property("Email")
92 | .IsRequired()
93 | .HasColumnType("nvarchar(100)")
94 | .HasMaxLength(100);
95 |
96 | b.Property("FirstName")
97 | .IsRequired()
98 | .HasColumnType("nvarchar(50)")
99 | .HasMaxLength(50);
100 |
101 | b.Property("Gender")
102 | .HasColumnType("bit");
103 |
104 | b.Property("LastName")
105 | .IsRequired()
106 | .HasColumnType("nvarchar(30)")
107 | .HasMaxLength(30);
108 |
109 | b.Property("Password")
110 | .IsRequired()
111 | .HasColumnType("nvarchar(100)")
112 | .HasMaxLength(100);
113 |
114 | b.Property("PhoneNo")
115 | .IsRequired()
116 | .HasColumnType("nvarchar(15)")
117 | .HasMaxLength(15);
118 |
119 | b.Property("UserName")
120 | .IsRequired()
121 | .HasColumnType("nvarchar(50)")
122 | .HasMaxLength(50);
123 |
124 | b.HasKey("Id");
125 |
126 | b.HasIndex("Email")
127 | .IsUnique();
128 |
129 | b.HasIndex("PhoneNo")
130 | .IsUnique();
131 |
132 | b.HasIndex("UserName")
133 | .IsUnique();
134 |
135 | b.ToTable("Users");
136 | });
137 | #pragma warning restore 612, 618
138 | }
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/Migrations/20200620070410_DepartmentDesignationMigration.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 |
3 | namespace APIFuelStation.Migrations
4 | {
5 | public partial class DepartmentDesignationMigration : Migration
6 | {
7 | protected override void Up(MigrationBuilder migrationBuilder)
8 | {
9 | migrationBuilder.CreateTable(
10 | name: "Departments",
11 | columns: table => new
12 | {
13 | Id = table.Column(nullable: false)
14 | .Annotation("SqlServer:Identity", "1, 1"),
15 | Name = table.Column(maxLength: 100, nullable: false),
16 | Code = table.Column(maxLength: 100, nullable: true),
17 | Description = table.Column(nullable: true)
18 | },
19 | constraints: table =>
20 | {
21 | table.PrimaryKey("PK_Departments", x => x.Id);
22 | });
23 |
24 | migrationBuilder.CreateTable(
25 | name: "Designations",
26 | columns: table => new
27 | {
28 | Id = table.Column(nullable: false)
29 | .Annotation("SqlServer:Identity", "1, 1"),
30 | Name = table.Column(maxLength: 100, nullable: false),
31 | Code = table.Column(maxLength: 100, nullable: true),
32 | Description = table.Column(nullable: true)
33 | },
34 | constraints: table =>
35 | {
36 | table.PrimaryKey("PK_Designations", x => x.Id);
37 | });
38 |
39 | migrationBuilder.CreateIndex(
40 | name: "IX_Departments_Code",
41 | table: "Departments",
42 | column: "Code",
43 | unique: true,
44 | filter: "[Code] IS NOT NULL");
45 |
46 | migrationBuilder.CreateIndex(
47 | name: "IX_Designations_Code",
48 | table: "Designations",
49 | column: "Code",
50 | unique: true,
51 | filter: "[Code] IS NOT NULL");
52 | }
53 |
54 | protected override void Down(MigrationBuilder migrationBuilder)
55 | {
56 | migrationBuilder.DropTable(
57 | name: "Departments");
58 |
59 | migrationBuilder.DropTable(
60 | name: "Designations");
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Migrations/20200623152632_EmployeeMigration.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using APIFuelStation.DbContexts;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Metadata;
7 | using Microsoft.EntityFrameworkCore.Migrations;
8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
9 |
10 | namespace APIFuelStation.Migrations
11 | {
12 | [DbContext(typeof(FuelDBContext))]
13 | [Migration("20200623152632_EmployeeMigration")]
14 | partial class EmployeeMigration
15 | {
16 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
17 | {
18 | #pragma warning disable 612, 618
19 | modelBuilder
20 | .HasAnnotation("ProductVersion", "3.1.5")
21 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
23 |
24 | modelBuilder.Entity("APIFuelStation.Models.Department", b =>
25 | {
26 | b.Property("Id")
27 | .ValueGeneratedOnAdd()
28 | .HasColumnType("int")
29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
30 |
31 | b.Property("Code")
32 | .HasColumnType("nvarchar(100)")
33 | .HasMaxLength(100);
34 |
35 | b.Property("Description")
36 | .HasColumnType("nvarchar(max)");
37 |
38 | b.Property("Name")
39 | .IsRequired()
40 | .HasColumnType("nvarchar(100)")
41 | .HasMaxLength(100);
42 |
43 | b.HasKey("Id");
44 |
45 | b.HasIndex("Code")
46 | .IsUnique()
47 | .HasFilter("[Code] IS NOT NULL");
48 |
49 | b.ToTable("Departments");
50 | });
51 |
52 | modelBuilder.Entity("APIFuelStation.Models.Designation", b =>
53 | {
54 | b.Property("Id")
55 | .ValueGeneratedOnAdd()
56 | .HasColumnType("int")
57 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
58 |
59 | b.Property("Code")
60 | .HasColumnType("nvarchar(100)")
61 | .HasMaxLength(100);
62 |
63 | b.Property("Description")
64 | .HasColumnType("nvarchar(max)");
65 |
66 | b.Property("Name")
67 | .IsRequired()
68 | .HasColumnType("nvarchar(100)")
69 | .HasMaxLength(100);
70 |
71 | b.HasKey("Id");
72 |
73 | b.HasIndex("Code")
74 | .IsUnique()
75 | .HasFilter("[Code] IS NOT NULL");
76 |
77 | b.ToTable("Designations");
78 | });
79 |
80 | modelBuilder.Entity("APIFuelStation.Models.Employee", b =>
81 | {
82 | b.Property("Id")
83 | .ValueGeneratedOnAdd()
84 | .HasColumnType("int")
85 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
86 |
87 | b.Property("Avatar")
88 | .HasColumnType("nvarchar(250)")
89 | .HasMaxLength(250);
90 |
91 | b.Property("DepartmentId")
92 | .HasColumnType("int");
93 |
94 | b.Property("DesignationId")
95 | .HasColumnType("int");
96 |
97 | b.Property("Email")
98 | .IsRequired()
99 | .HasColumnType("nvarchar(100)")
100 | .HasMaxLength(100);
101 |
102 | b.Property("FirstName")
103 | .IsRequired()
104 | .HasColumnType("nvarchar(50)")
105 | .HasMaxLength(50);
106 |
107 | b.Property("Gender")
108 | .HasColumnType("bit");
109 |
110 | b.Property("JoiningDate")
111 | .HasColumnType("nvarchar(max)");
112 |
113 | b.Property("LastName")
114 | .IsRequired()
115 | .HasColumnType("nvarchar(30)")
116 | .HasMaxLength(30);
117 |
118 | b.Property("Password")
119 | .HasColumnType("nvarchar(100)")
120 | .HasMaxLength(100);
121 |
122 | b.Property("PhoneNo")
123 | .IsRequired()
124 | .HasColumnType("nvarchar(15)")
125 | .HasMaxLength(15);
126 |
127 | b.Property("UserName")
128 | .IsRequired()
129 | .HasColumnType("nvarchar(50)")
130 | .HasMaxLength(50);
131 |
132 | b.HasKey("Id");
133 |
134 | b.HasIndex("DepartmentId");
135 |
136 | b.HasIndex("DesignationId");
137 |
138 | b.ToTable("Employees");
139 | });
140 |
141 | modelBuilder.Entity("APIFuelStation.Models.User", b =>
142 | {
143 | b.Property("Id")
144 | .ValueGeneratedOnAdd()
145 | .HasColumnType("int")
146 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
147 |
148 | b.Property("Avatar")
149 | .IsRequired()
150 | .HasColumnType("nvarchar(250)")
151 | .HasMaxLength(250);
152 |
153 | b.Property("Email")
154 | .IsRequired()
155 | .HasColumnType("nvarchar(100)")
156 | .HasMaxLength(100);
157 |
158 | b.Property("FirstName")
159 | .IsRequired()
160 | .HasColumnType("nvarchar(50)")
161 | .HasMaxLength(50);
162 |
163 | b.Property("Gender")
164 | .HasColumnType("bit");
165 |
166 | b.Property("LastName")
167 | .IsRequired()
168 | .HasColumnType("nvarchar(30)")
169 | .HasMaxLength(30);
170 |
171 | b.Property("Password")
172 | .IsRequired()
173 | .HasColumnType("nvarchar(100)")
174 | .HasMaxLength(100);
175 |
176 | b.Property("PhoneNo")
177 | .IsRequired()
178 | .HasColumnType("nvarchar(15)")
179 | .HasMaxLength(15);
180 |
181 | b.Property("UserName")
182 | .IsRequired()
183 | .HasColumnType("nvarchar(50)")
184 | .HasMaxLength(50);
185 |
186 | b.HasKey("Id");
187 |
188 | b.HasIndex("Email")
189 | .IsUnique();
190 |
191 | b.HasIndex("PhoneNo")
192 | .IsUnique();
193 |
194 | b.HasIndex("UserName")
195 | .IsUnique();
196 |
197 | b.ToTable("Users");
198 | });
199 |
200 | modelBuilder.Entity("APIFuelStation.Models.Employee", b =>
201 | {
202 | b.HasOne("APIFuelStation.Models.Department", "Department")
203 | .WithMany()
204 | .HasForeignKey("DepartmentId");
205 |
206 | b.HasOne("APIFuelStation.Models.Designation", "Designation")
207 | .WithMany()
208 | .HasForeignKey("DesignationId");
209 | });
210 | #pragma warning restore 612, 618
211 | }
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/Migrations/20200623152632_EmployeeMigration.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 |
3 | namespace APIFuelStation.Migrations
4 | {
5 | public partial class EmployeeMigration : Migration
6 | {
7 | protected override void Up(MigrationBuilder migrationBuilder)
8 | {
9 | migrationBuilder.CreateTable(
10 | name: "Employees",
11 | columns: table => new
12 | {
13 | Id = table.Column(nullable: false)
14 | .Annotation("SqlServer:Identity", "1, 1"),
15 | FirstName = table.Column(maxLength: 50, nullable: false),
16 | LastName = table.Column(maxLength: 30, nullable: false),
17 | UserName = table.Column(maxLength: 50, nullable: false),
18 | Email = table.Column(maxLength: 100, nullable: false),
19 | PhoneNo = table.Column(maxLength: 15, nullable: false),
20 | Gender = table.Column(nullable: false),
21 | Password = table.Column(maxLength: 100, nullable: true),
22 | Avatar = table.Column(maxLength: 250, nullable: true),
23 | JoiningDate = table.Column(nullable: true),
24 | DesignationId = table.Column(nullable: true),
25 | DepartmentId = table.Column(nullable: true)
26 | },
27 | constraints: table =>
28 | {
29 | table.PrimaryKey("PK_Employees", x => x.Id);
30 | table.ForeignKey(
31 | name: "FK_Employees_Departments_DepartmentId",
32 | column: x => x.DepartmentId,
33 | principalTable: "Departments",
34 | principalColumn: "Id",
35 | onDelete: ReferentialAction.Restrict);
36 | table.ForeignKey(
37 | name: "FK_Employees_Designations_DesignationId",
38 | column: x => x.DesignationId,
39 | principalTable: "Designations",
40 | principalColumn: "Id",
41 | onDelete: ReferentialAction.Restrict);
42 | });
43 |
44 | migrationBuilder.CreateIndex(
45 | name: "IX_Employees_DepartmentId",
46 | table: "Employees",
47 | column: "DepartmentId");
48 |
49 | migrationBuilder.CreateIndex(
50 | name: "IX_Employees_DesignationId",
51 | table: "Employees",
52 | column: "DesignationId");
53 | }
54 |
55 | protected override void Down(MigrationBuilder migrationBuilder)
56 | {
57 | migrationBuilder.DropTable(
58 | name: "Employees");
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Migrations/FuelDBContextModelSnapshot.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using APIFuelStation.DbContexts;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Metadata;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace APIFuelStation.Migrations
10 | {
11 | [DbContext(typeof(FuelDBContext))]
12 | partial class FuelDBContextModelSnapshot : ModelSnapshot
13 | {
14 | protected override void BuildModel(ModelBuilder modelBuilder)
15 | {
16 | #pragma warning disable 612, 618
17 | modelBuilder
18 | .HasAnnotation("ProductVersion", "3.1.5")
19 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
20 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
21 |
22 | modelBuilder.Entity("APIFuelStation.Models.Department", b =>
23 | {
24 | b.Property("Id")
25 | .ValueGeneratedOnAdd()
26 | .HasColumnType("int")
27 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
28 |
29 | b.Property("Code")
30 | .HasColumnType("nvarchar(100)")
31 | .HasMaxLength(100);
32 |
33 | b.Property("Description")
34 | .HasColumnType("nvarchar(max)");
35 |
36 | b.Property("Name")
37 | .IsRequired()
38 | .HasColumnType("nvarchar(100)")
39 | .HasMaxLength(100);
40 |
41 | b.HasKey("Id");
42 |
43 | b.HasIndex("Code")
44 | .IsUnique()
45 | .HasFilter("[Code] IS NOT NULL");
46 |
47 | b.ToTable("Departments");
48 | });
49 |
50 | modelBuilder.Entity("APIFuelStation.Models.Designation", b =>
51 | {
52 | b.Property("Id")
53 | .ValueGeneratedOnAdd()
54 | .HasColumnType("int")
55 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
56 |
57 | b.Property("Code")
58 | .HasColumnType("nvarchar(100)")
59 | .HasMaxLength(100);
60 |
61 | b.Property("Description")
62 | .HasColumnType("nvarchar(max)");
63 |
64 | b.Property("Name")
65 | .IsRequired()
66 | .HasColumnType("nvarchar(100)")
67 | .HasMaxLength(100);
68 |
69 | b.HasKey("Id");
70 |
71 | b.HasIndex("Code")
72 | .IsUnique()
73 | .HasFilter("[Code] IS NOT NULL");
74 |
75 | b.ToTable("Designations");
76 | });
77 |
78 | modelBuilder.Entity("APIFuelStation.Models.Employee", b =>
79 | {
80 | b.Property("Id")
81 | .ValueGeneratedOnAdd()
82 | .HasColumnType("int")
83 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
84 |
85 | b.Property("Avatar")
86 | .HasColumnType("nvarchar(250)")
87 | .HasMaxLength(250);
88 |
89 | b.Property("DepartmentId")
90 | .HasColumnType("int");
91 |
92 | b.Property("DesignationId")
93 | .HasColumnType("int");
94 |
95 | b.Property("Email")
96 | .IsRequired()
97 | .HasColumnType("nvarchar(100)")
98 | .HasMaxLength(100);
99 |
100 | b.Property("FirstName")
101 | .IsRequired()
102 | .HasColumnType("nvarchar(50)")
103 | .HasMaxLength(50);
104 |
105 | b.Property("Gender")
106 | .HasColumnType("bit");
107 |
108 | b.Property("JoiningDate")
109 | .HasColumnType("nvarchar(max)");
110 |
111 | b.Property("LastName")
112 | .IsRequired()
113 | .HasColumnType("nvarchar(30)")
114 | .HasMaxLength(30);
115 |
116 | b.Property("Password")
117 | .HasColumnType("nvarchar(100)")
118 | .HasMaxLength(100);
119 |
120 | b.Property("PhoneNo")
121 | .IsRequired()
122 | .HasColumnType("nvarchar(15)")
123 | .HasMaxLength(15);
124 |
125 | b.Property("UserName")
126 | .IsRequired()
127 | .HasColumnType("nvarchar(50)")
128 | .HasMaxLength(50);
129 |
130 | b.HasKey("Id");
131 |
132 | b.HasIndex("DepartmentId");
133 |
134 | b.HasIndex("DesignationId");
135 |
136 | b.ToTable("Employees");
137 | });
138 |
139 | modelBuilder.Entity("APIFuelStation.Models.User", b =>
140 | {
141 | b.Property("Id")
142 | .ValueGeneratedOnAdd()
143 | .HasColumnType("int")
144 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
145 |
146 | b.Property("Avatar")
147 | .IsRequired()
148 | .HasColumnType("nvarchar(250)")
149 | .HasMaxLength(250);
150 |
151 | b.Property("Email")
152 | .IsRequired()
153 | .HasColumnType("nvarchar(100)")
154 | .HasMaxLength(100);
155 |
156 | b.Property("FirstName")
157 | .IsRequired()
158 | .HasColumnType("nvarchar(50)")
159 | .HasMaxLength(50);
160 |
161 | b.Property("Gender")
162 | .HasColumnType("bit");
163 |
164 | b.Property("LastName")
165 | .IsRequired()
166 | .HasColumnType("nvarchar(30)")
167 | .HasMaxLength(30);
168 |
169 | b.Property("Password")
170 | .IsRequired()
171 | .HasColumnType("nvarchar(100)")
172 | .HasMaxLength(100);
173 |
174 | b.Property("PhoneNo")
175 | .IsRequired()
176 | .HasColumnType("nvarchar(15)")
177 | .HasMaxLength(15);
178 |
179 | b.Property("UserName")
180 | .IsRequired()
181 | .HasColumnType("nvarchar(50)")
182 | .HasMaxLength(50);
183 |
184 | b.HasKey("Id");
185 |
186 | b.HasIndex("Email")
187 | .IsUnique();
188 |
189 | b.HasIndex("PhoneNo")
190 | .IsUnique();
191 |
192 | b.HasIndex("UserName")
193 | .IsUnique();
194 |
195 | b.ToTable("Users");
196 | });
197 |
198 | modelBuilder.Entity("APIFuelStation.Models.Employee", b =>
199 | {
200 | b.HasOne("APIFuelStation.Models.Department", "Department")
201 | .WithMany()
202 | .HasForeignKey("DepartmentId");
203 |
204 | b.HasOne("APIFuelStation.Models.Designation", "Designation")
205 | .WithMany()
206 | .HasForeignKey("DesignationId");
207 | });
208 | #pragma warning restore 612, 618
209 | }
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/Models/Department.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.DataAnnotations;
3 |
4 | namespace APIFuelStation.Models
5 | {
6 | public class Department
7 | {
8 | [Key]
9 | public int Id { get; set; }
10 |
11 | [Required]
12 | [MaxLength(100)]
13 | public string Name { get; set; }
14 |
15 | [MaxLength(100)]
16 | public string? Code { get; set; }
17 |
18 | public string? Description { get; set; }
19 | }
20 | }
--------------------------------------------------------------------------------
/Models/Designation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.DataAnnotations;
3 |
4 | namespace APIFuelStation.Models {
5 | public class Designation {
6 | [Key]
7 | public int Id { get; set; }
8 |
9 | [Required]
10 | [MaxLength (100)]
11 | public string Name { get; set; }
12 |
13 | [MaxLength (100)]
14 | public string? Code { get; set; }
15 |
16 | public string? Description { get; set; }
17 |
18 | }
19 | }
--------------------------------------------------------------------------------
/Models/Employee.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations;
2 |
3 | namespace APIFuelStation.Models {
4 | public class Employee {
5 | [Key]
6 | public int Id { get; set; }
7 |
8 | [Required]
9 | [MaxLength (50)]
10 | public string FirstName { get; set; }
11 |
12 | [Required]
13 | [MaxLength (30)]
14 | public string LastName { get; set; }
15 |
16 | [Required]
17 | [MaxLength (50)]
18 | public string UserName { get; set; }
19 |
20 | [Required]
21 | [MaxLength (100)]
22 | public string Email { get; set; }
23 |
24 | [Required]
25 | [MaxLength (15)]
26 | public string PhoneNo { get; set; }
27 |
28 | [Required]
29 | public bool Gender { get; set; }
30 |
31 | [MaxLength (100)]
32 | public string? Password { get; set; }
33 |
34 | [MaxLength (250)]
35 | public string? Avatar { get; set; }
36 |
37 | [DataType (DataType.Date)]
38 | [DisplayFormat (DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
39 | public string? JoiningDate { get; set; }
40 |
41 | public int? DesignationId { get; set; }
42 | public int? DepartmentId { get; set; }
43 | // public Department Department { get; set; }
44 | // public Designation Designation { get; set; }
45 | }
46 | }
--------------------------------------------------------------------------------
/Models/User.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations;
2 |
3 | namespace APIFuelStation.Models {
4 | public class User {
5 | [Key]
6 | public int Id { get; set; }
7 |
8 | [Required]
9 | [MaxLength (50)]
10 | public string FirstName { get; set; }
11 |
12 | [Required]
13 | [MaxLength (30)]
14 | public string LastName { get; set; }
15 |
16 | [Required]
17 | [MaxLength (50)]
18 | public string UserName { get; set; }
19 |
20 | [Required]
21 | [MaxLength (100)]
22 | public string Email { get; set; }
23 |
24 | [Required]
25 | [MaxLength (15)]
26 | public string PhoneNo { get; set; }
27 |
28 | [Required]
29 | [MaxLength (100)]
30 | public string Password { get; set; }
31 |
32 | [Required]
33 | [MaxLength (250)]
34 | public string Avatar { get; set; }
35 |
36 | [Required]
37 | public bool Gender { get; set; }
38 | }
39 | }
--------------------------------------------------------------------------------
/ModelsValidator/DepartmentValidator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using FluentValidation;
7 |
8 | namespace APIFuelStation.ModelsValidator {
9 |
10 | public class DepartmentValidator : AbstractValidator {
11 |
12 | private readonly IDepartmentRepository _departmentRepository;
13 | public DepartmentValidator (IDepartmentRepository departmentRepository) {
14 | _departmentRepository = departmentRepository;
15 |
16 | RuleFor (department => department.Name).NotNull ().WithMessage ("Please give department name");
17 | RuleFor (department => department.Code).Must (IsCodeUnique).WithMessage ("Code Already Exists, Please give a new code");
18 | }
19 |
20 | public bool IsCodeUnique (Department editedUser, string newValue) {
21 | var departmentSearchByCode = _departmentRepository.GetDepartmentByCode (newValue);
22 | if (departmentSearchByCode == null)
23 | return true;
24 | return false;
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/ModelsValidator/DesignationValidator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using FluentValidation;
7 |
8 | namespace APIFuelStation.ModelsValidator
9 | {
10 |
11 | public class DesignationValidator : AbstractValidator
12 | {
13 |
14 | private readonly IDesignationRepository _designationRepository;
15 | public DesignationValidator(IDesignationRepository designationRepository)
16 | {
17 | _designationRepository = designationRepository;
18 |
19 | RuleFor(designation => designation.Name).NotNull().WithMessage("Please give designation name");
20 | RuleFor(designation => designation.Code).Must(IsCodeUnique).WithMessage("Code Already Exists, Please give a new code");
21 | }
22 |
23 | public bool IsCodeUnique(Designation editedUser, string newValue)
24 | {
25 | var designationSearchByCode = _designationRepository.GetDesignationByCode(newValue);
26 | if (designationSearchByCode == null)
27 | return true;
28 | return false;
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/ModelsValidator/EmployeeValidator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using FluentValidation;
7 |
8 | namespace APIFuelStation.ModelsValidator {
9 |
10 | public class EmployeeValidator : AbstractValidator {
11 |
12 | private readonly IEmployeeRepository _employeeRepository;
13 | public EmployeeValidator (IEmployeeRepository employeeRepository) {
14 | _employeeRepository = employeeRepository;
15 |
16 | RuleFor (employee => employee.FirstName).NotNull ().WithMessage ("Please give your first name");
17 | RuleFor (employee => employee.LastName).NotNull ().WithMessage ("Please give your last name");
18 | RuleFor (employee => employee.PhoneNo).Length (11).WithMessage ("Please give your phone number of 11 digits");
19 | RuleFor (employee => employee.Email).NotNull ().EmailAddress ().WithMessage ("Please give your valid email address");
20 | RuleFor (employee => employee.Email).Must (IsEmailUnique).WithMessage ("Email already exists, Please give a new email address");
21 | }
22 |
23 | public bool IsEmailUnique (Employee editedEmployee, string newValue) {
24 | var employeeSearchByEmail = _employeeRepository.GetEmployeeByEmail (newValue);
25 | if (employeeSearchByEmail == null)
26 | return true;
27 | return false;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/ModelsValidator/UserValidator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using APIFuelStation.IRepositories;
5 | using APIFuelStation.Models;
6 | using FluentValidation;
7 |
8 | namespace APIFuelStation.ModelsValidator
9 | {
10 |
11 | public class UserValidator : AbstractValidator
12 | {
13 |
14 | private readonly IUserRepository _userRepository;
15 | public UserValidator(IUserRepository userRepository)
16 | {
17 | _userRepository = userRepository;
18 |
19 | RuleFor(user => user.FirstName).NotNull().WithMessage("Please give your first name");
20 | RuleFor(user => user.LastName).NotNull().WithMessage("Please give your last name");
21 | RuleFor(user => user.PhoneNo).Length(11).WithMessage("Please give your phone number of 11 digits");
22 | RuleFor(user => user.Password).MinimumLength(8).WithMessage("Please give your password at least 8 characters");
23 | RuleFor(user => user.Email).NotNull().EmailAddress().WithMessage("Please give your valid email address");
24 | RuleFor(user => user.Email).Must(IsEmailUnique).WithMessage("Email already exists, Please give a new email address");
25 | }
26 |
27 | public bool IsEmailUnique(User editedUser, string newValue)
28 | {
29 | var userSearchByEmail = _userRepository.GetUserByEmail(newValue);
30 | if (userSearchByEmail == null)
31 | return true;
32 | return false;
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.Extensions.Configuration;
7 | using Microsoft.Extensions.Hosting;
8 | using Microsoft.Extensions.Logging;
9 |
10 | namespace APIFuelStation
11 | {
12 | public class Program
13 | {
14 | public static void Main(string[] args)
15 | {
16 | CreateHostBuilder(args).Build().Run();
17 | }
18 |
19 | public static IHostBuilder CreateHostBuilder(string[] args) =>
20 | Host.CreateDefaultBuilder(args)
21 | .ConfigureWebHostDefaults(webBuilder =>
22 | {
23 | webBuilder.UseStartup();
24 | });
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:34044",
8 | "sslPort": 44355
9 | }
10 | },
11 | "profiles": {
12 | "IIS Express": {
13 | "commandName": "IISExpress",
14 | "launchBrowser": true,
15 | "launchUrl": "weatherforecast",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "APIFuelStation": {
21 | "commandName": "Project",
22 | "launchBrowser": true,
23 | "launchUrl": "weatherforecast",
24 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
25 | "environmentVariables": {
26 | "ASPNETCORE_ENVIRONMENT": "Development"
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/QueryBus/Queries/Department/GetAllDepartmentQuery.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using APIFuelStation.Models;
3 |
4 | namespace APIFuelStation.QueryBus
5 | {
6 | public class GetAllDepartmentQuery : MediatR.IRequest>
7 | {
8 |
9 | }
10 | }
--------------------------------------------------------------------------------
/QueryBus/Queries/Department/GetSingleDepartmentQuery.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using APIFuelStation.Models;
3 |
4 | namespace APIFuelStation.QueryBus
5 | {
6 | public class GetSingleDepartmentQuery : MediatR.IRequest
7 | {
8 | public GetSingleDepartmentQuery(int id)
9 | {
10 | this.Id = id;
11 | }
12 |
13 | public int Id { get; }
14 | }
15 | }
--------------------------------------------------------------------------------
/QueryBus/Queries/Designation/GetAllDesignationQuery.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using APIFuelStation.Models;
3 |
4 | namespace APIFuelStation.QueryBus
5 | {
6 | public class GetAllDesignationQuery : MediatR.IRequest>
7 | {
8 |
9 | }
10 | }
--------------------------------------------------------------------------------
/QueryBus/Queries/Designation/GetSingleDesignationQuery.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using APIFuelStation.Models;
3 |
4 | namespace APIFuelStation.QueryBus
5 | {
6 | public class GetSingleDesignationQuery : MediatR.IRequest
7 | {
8 | public GetSingleDesignationQuery(int id)
9 | {
10 | this.Id = id;
11 | }
12 |
13 | public int Id { get; }
14 | }
15 | }
--------------------------------------------------------------------------------
/QueryBus/Queries/Employee/GetAllEmployeeQuery.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using APIFuelStation.Models;
3 |
4 | namespace APIFuelStation.QueryBus.Queries {
5 | public class GetAllEmployeeQuery : MediatR.IRequest> {
6 |
7 | }
8 | }
--------------------------------------------------------------------------------
/QueryBus/Queries/Employee/GetSingleEmployeeQuery.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using APIFuelStation.Models;
3 |
4 | namespace APIFuelStation.QueryBus.Queries {
5 | public class GetSingleEmployeeQuery : MediatR.IRequest