├── .github └── workflows │ └── dotnet.yml ├── .gitignore ├── AngularAutoSaveCommands.sln ├── AutoSaveCommandsAngular ├── .angulardoc.json ├── .browserslistrc ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── certs │ ├── Readme.md │ ├── dev_localhost.key │ ├── dev_localhost.pem │ └── dev_localhost.pfx ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── about │ │ │ ├── about-data.ts │ │ │ ├── about.component.html │ │ │ └── about.component.ts │ │ ├── app.component.html │ │ ├── app.component.scss │ │ ├── app.component.ts │ │ ├── app.constants.ts │ │ ├── app.module.ts │ │ ├── app.routes.ts │ │ ├── commands │ │ │ ├── commands.component.html │ │ │ └── commands.component.ts │ │ ├── home │ │ │ ├── home-data.ts │ │ │ ├── home.component.html │ │ │ └── home.component.ts │ │ ├── httprequests │ │ │ ├── httprequests.component.html │ │ │ └── httprequests.component.ts │ │ └── services │ │ │ ├── about-data-service.ts │ │ │ ├── command-dto.ts │ │ │ ├── command-service.ts │ │ │ └── home-data-service.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.scss │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json ├── AutoSaveCommandsApi ├── ActionFilters │ └── ValidateCommandDtoFilter.cs ├── AutoSaveCommandsApi.csproj ├── Controllers │ ├── AboutController.cs │ ├── CommandController.cs │ └── HomeController.cs ├── DomainModelMsSqlServerContext.cs ├── Migrations │ ├── 20180616095050_init.Designer.cs │ ├── 20180616095050_init.cs │ └── DomainModelMsSqlServerContextModelSnapshot.cs ├── Models │ ├── AboutData.cs │ ├── CommandDto.cs │ ├── CommandEntity.cs │ ├── CommandTypes.cs │ ├── HomeData.cs │ └── PayloadTypes.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Providers │ ├── CommandDataAccessProvider.cs │ ├── CommandHandler.cs │ ├── Commands │ │ ├── AddAboutDataCommand.cs │ │ ├── AddHomeDataCommand.cs │ │ ├── DeleteAboutDataCommand.cs │ │ ├── DeleteHomeDataCommand.cs │ │ ├── ICommand.cs │ │ ├── ICommandAdd.cs │ │ ├── UpdateAboutDataCommand.cs │ │ └── UpdateHomeDataCommand.cs │ ├── ICommandDataAccessProvider.cs │ └── ICommandHandler.cs ├── Startup.cs ├── appsettings.Development.json └── appsettings.json ├── LICENSE └── README.md /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | name: .NET 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Setup .NET 17 | uses: actions/setup-dotnet@v1 18 | with: 19 | dotnet-version: 5.0.x 20 | - name: Restore dependencies 21 | run: dotnet restore 22 | - name: Build 23 | run: dotnet build --no-restore 24 | - name: Test 25 | run: dotnet test --no-build --verbosity normal 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /AngularAutoSaveCommands/wwwroot/ 3 | /AngularAutoSaveCommands/node_modules/ 4 | /.vs 5 | /AngularAutoSaveCommands/obj 6 | /AngularAutoSaveCommands/bin 7 | /AngularAutoSaveCommands/angularApp/**/*.js.map 8 | /AngularAutoSaveCommands/angularApp/**/*.js 9 | /AngularAutoSaveCommands/AngularAutoSaveCommands.csproj.user 10 | **/bin 11 | **/obj 12 | -------------------------------------------------------------------------------- /AngularAutoSaveCommands.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{70616875-81BE-4439-90FC-B0CE42099D50}" 7 | ProjectSection(SolutionItems) = preProject 8 | README.md = README.md 9 | EndProjectSection 10 | EndProject 11 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoSaveCommandsApi", "AutoSaveCommandsApi\AutoSaveCommandsApi.csproj", "{7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Debug|x64 = Debug|x64 17 | Debug|x86 = Debug|x86 18 | Release|Any CPU = Release|Any CPU 19 | Release|x64 = Release|x64 20 | Release|x86 = Release|x86 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Debug|x64.ActiveCfg = Debug|Any CPU 26 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Debug|x64.Build.0 = Debug|Any CPU 27 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Debug|x86.ActiveCfg = Debug|Any CPU 28 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Debug|x86.Build.0 = Debug|Any CPU 29 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Release|x64.ActiveCfg = Release|Any CPU 32 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Release|x64.Build.0 = Release|Any CPU 33 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Release|x86.ActiveCfg = Release|Any CPU 34 | {7E97FEDD-5AFB-4A2C-AD11-692065B71A0E}.Release|x86.Build.0 = Release|Any CPU 35 | EndGlobalSection 36 | GlobalSection(SolutionProperties) = preSolution 37 | HideSolutionNode = FALSE 38 | EndGlobalSection 39 | GlobalSection(ExtensibilityGlobals) = postSolution 40 | SolutionGuid = {5DDA0B1A-998B-4F54-8653-3EFA6B97AF8A} 41 | EndGlobalSection 42 | EndGlobal 43 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/.angulardoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "repoId": "0c7e1bf5-1a45-49b4-ac3a-249144ac0cab", 3 | "lastSync": 0 4 | } -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line. 18 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/README.md: -------------------------------------------------------------------------------- 1 | # AutoSaveCommandsAngular 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.0.7. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. 28 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "AutoSaveCommandsAngular": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | }, 12 | "@schematics/angular:application": { 13 | "strict": true 14 | } 15 | }, 16 | "root": "", 17 | "sourceRoot": "src", 18 | "prefix": "app", 19 | "architect": { 20 | "build": { 21 | "builder": "@angular-devkit/build-angular:browser", 22 | "options": { 23 | "outputPath": "dist/AutoSaveCommandsAngular", 24 | "index": "src/index.html", 25 | "main": "src/main.ts", 26 | "polyfills": "src/polyfills.ts", 27 | "tsConfig": "tsconfig.app.json", 28 | "aot": true, 29 | "assets": [ 30 | "src/favicon.ico", 31 | "src/assets" 32 | ], 33 | "styles": [ 34 | "src/styles.scss" 35 | ], 36 | "scripts": [ 37 | "node_modules/jquery/dist/jquery.min.js", 38 | "node_modules/bootstrap/dist/js/bootstrap.min.js" 39 | ] 40 | }, 41 | "configurations": { 42 | "production": { 43 | "fileReplacements": [ 44 | { 45 | "replace": "src/environments/environment.ts", 46 | "with": "src/environments/environment.prod.ts" 47 | } 48 | ], 49 | "optimization": true, 50 | "outputHashing": "all", 51 | "sourceMap": false, 52 | "namedChunks": false, 53 | "extractLicenses": true, 54 | "vendorChunk": false, 55 | "buildOptimizer": true, 56 | "budgets": [ 57 | { 58 | "type": "initial", 59 | "maximumWarning": "500kb", 60 | "maximumError": "1mb" 61 | }, 62 | { 63 | "type": "anyComponentStyle", 64 | "maximumWarning": "2kb", 65 | "maximumError": "4kb" 66 | } 67 | ] 68 | } 69 | } 70 | }, 71 | "serve": { 72 | "builder": "@angular-devkit/build-angular:dev-server", 73 | "options": { 74 | "browserTarget": "AutoSaveCommandsAngular:build", 75 | "sslKey": "certs/dev_localhost.key", 76 | "sslCert": "certs/dev_localhost.pem" 77 | }, 78 | "configurations": { 79 | "production": { 80 | "browserTarget": "AutoSaveCommandsAngular:build:production" 81 | } 82 | } 83 | }, 84 | "extract-i18n": { 85 | "builder": "@angular-devkit/build-angular:extract-i18n", 86 | "options": { 87 | "browserTarget": "AutoSaveCommandsAngular:build" 88 | } 89 | }, 90 | "test": { 91 | "builder": "@angular-devkit/build-angular:karma", 92 | "options": { 93 | "main": "src/test.ts", 94 | "polyfills": "src/polyfills.ts", 95 | "tsConfig": "tsconfig.spec.json", 96 | "karmaConfig": "karma.conf.js", 97 | "assets": [ 98 | "src/favicon.ico", 99 | "src/assets" 100 | ], 101 | "styles": [ 102 | "src/styles.scss" 103 | ], 104 | "scripts": [] 105 | } 106 | }, 107 | "lint": { 108 | "builder": "@angular-devkit/build-angular:tslint", 109 | "options": { 110 | "tsConfig": [ 111 | "tsconfig.app.json", 112 | "tsconfig.spec.json", 113 | "e2e/tsconfig.json" 114 | ], 115 | "exclude": [ 116 | "**/node_modules/**" 117 | ] 118 | } 119 | }, 120 | "e2e": { 121 | "builder": "@angular-devkit/build-angular:protractor", 122 | "options": { 123 | "protractorConfig": "e2e/protractor.conf.js", 124 | "devServerTarget": "AutoSaveCommandsAngular:serve" 125 | }, 126 | "configurations": { 127 | "production": { 128 | "devServerTarget": "AutoSaveCommandsAngular:serve:production" 129 | } 130 | } 131 | } 132 | } 133 | } 134 | }, 135 | "defaultProject": "AutoSaveCommandsAngular" 136 | } 137 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/certs/Readme.md: -------------------------------------------------------------------------------- 1 | double click the pfx on a windows mc and use the 1234 password to install. 2 | 3 | The certificates are configured in the angular.json -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/certs/dev_localhost.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXQIBAAKBgQCs7HI0KWqXEjH1fxXdkgVHg+1UgbtBhwkeZ3WhBsTGcwlqGUmzqlhKiR2hTd9G 3 | dMhQm1tFeU9qAMpmglxR+XgoZoEv9uoXw/TeegdKvn1V3exTxeULIDGJOXK6wQ1M+4FLMr7zBWlM 4 | hWmqcbYTHHVwwYd+ycDRHU3NAIxDfMUSQQIDAQABAoGAIB8z/7iJ0lJQ8XeQCj6ruGMrXP1UWZHK 5 | AdnaIfVt7CdGYm0cIcHM8NuTo3khtqbO5xpU1Az60YggEPa6S4f558kGBIg4PQVxgE/Kv77ptGAk 6 | rZG9FaCyIibGMh5aJLtxG0Fh1FGnuK1Xk1BKXtaGRUkZpKGg4rMJ9w3qp/T5vLkCQQDe+FiMqY2s 7 | pxHEz+h3NJ0H2T81FCx2upf1fjTVtlQnJ7Gds6eZT0zwa3z1bSw+VkxICERY8C43bzPUJUgPIyLX 8 | AkEAxooyVkJHmxlcIvZfrZPvQs+2GOXpWVnyjNUWf8t9G2MsmkdGIkp7oJhi5obpdNR+3jQe0xyr 9 | Dvy1hbHuGp5opwJBALO6Zc5EogGozgbiPBVSoL2B3ZRQhaLSt8jYCYi3JtBFC8P927wVkwQ88IX4 10 | kXBSKbzqhQVX3Tkr9xArWRFylhMCQFmigt9WxSVM6cAPI1smctrjE/9hrVxds5fJjILdx/nZaIWu 11 | sAdDQVVb9yrEthm85hpDxbbiNohppzpY/nqeEfkCQQDInS/pP5dYTUxFV+/YweK+6smN2v+dYZAi 12 | 5KShWRl5fwpl+mdJT3aziRb/kfYkhGPQMO06OnGzjNKt7Rg0Z8mD 13 | -----END RSA PRIVATE KEY----- 14 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/certs/dev_localhost.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICQDCCAamgAwIBAgIJAIKGapdMCt4NMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNVBAMTCWxvY2Fs 3 | aG9zdDAeFw0yMDAyMjAyMjU3MjFaFw0zMDAyMjEyMjU3MjFaMBQxEjAQBgNVBAMTCWxvY2FsaG9z 4 | dDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEArOxyNClqlxIx9X8V3ZIFR4PtVIG7QYcJHmd1 5 | oQbExnMJahlJs6pYSokdoU3fRnTIUJtbRXlPagDKZoJcUfl4KGaBL/bqF8P03noHSr59Vd3sU8Xl 6 | CyAxiTlyusENTPuBSzK+8wVpTIVpqnG2Exx1cMGHfsnA0R1NzQCMQ3zFEkECAwEAAaOBmTCBljAS 7 | BgNVHRMBAf8ECDAGAQH/AgEDMA4GA1UdDwEB/wQEAwIB/jAUBgNVHREEDTALgglsb2NhbGhvc3Qw 8 | OwYDVR0lBDQwMgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEFBQcDAwYIKwYBBQUHAwQGCCsGAQUF 9 | BwMIMB0GA1UdDgQWBBQaVighscgq5k8BjEzeSsZp+6RxITANBgkqhkiG9w0BAQsFAAOBgQBXH/Sq 10 | jekwz+O0eG0zA2MA2LSwt7OELi54vATFYkXO45IO5frRagUTWDkx85/Vfm9OcdfoaHD1UzPkGBU0 11 | BPsnN3SGCB3Pk5jSRaXIBBiqByDFiP+G6EYmUYhLxB3FpJp6S5KlnQtdtLkl3KuT8KBtc9haro+e 12 | lDlUx5s/FM3SJw== 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/certs/dev_localhost.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienbod/AngularAutoSaveCommands/4bfd8259b50bfb2f5cf7016c2cf2f04351a02bcf/AutoSaveCommandsAngular/certs/dev_localhost.pfx -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | SELENIUM_PROMISE_MANAGER: false, 20 | baseUrl: 'http://localhost:4200/', 21 | framework: 'jasmine', 22 | jasmineNodeOpts: { 23 | showColors: true, 24 | defaultTimeoutInterval: 30000, 25 | print: function() {} 26 | }, 27 | onPrepare() { 28 | require('ts-node').register({ 29 | project: require('path').join(__dirname, './tsconfig.json') 30 | }); 31 | jasmine.getEnv().addReporter(new SpecReporter({ 32 | spec: { 33 | displayStacktrace: StacktraceOption.PRETTY 34 | } 35 | })); 36 | } 37 | }; -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', async () => { 12 | await page.navigateTo(); 13 | expect(await page.getTitleText()).toEqual('AutoSaveCommandsAngular app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | async navigateTo(): Promise { 5 | return browser.get(browser.baseUrl); 6 | } 7 | 8 | async getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "../tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "../out-tsc/e2e", 6 | "module": "commonjs", 7 | "target": "es2018", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/AutoSaveCommandsAngular'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auto-save-commands-angular", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve --ssl true -o", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~11.0.9", 15 | "@angular/common": "~11.0.9", 16 | "@angular/compiler": "~11.0.9", 17 | "@angular/core": "~11.0.9", 18 | "@angular/forms": "~11.0.9", 19 | "@angular/platform-browser": "~11.0.9", 20 | "@angular/platform-browser-dynamic": "~11.0.9", 21 | "@angular/router": "~11.0.9", 22 | "bootstrap": "^4.5.3", 23 | "jquery": "^3.5.1", 24 | "popper.js": "^1.16.1", 25 | "rxjs": "~6.6.0", 26 | "tslib": "^2.0.0", 27 | "zone.js": "~0.10.2" 28 | }, 29 | "devDependencies": { 30 | "@angular-devkit/build-angular": "~0.1100.7", 31 | "@angular/cli": "~11.0.7", 32 | "@angular/compiler-cli": "~11.0.9", 33 | "@types/jasmine": "~3.6.0", 34 | "@types/node": "^12.11.1", 35 | "codelyzer": "^6.0.0", 36 | "jasmine-core": "~3.6.0", 37 | "jasmine-spec-reporter": "~5.0.0", 38 | "karma": "~5.1.0", 39 | "karma-chrome-launcher": "~3.1.0", 40 | "karma-coverage": "~2.0.3", 41 | "karma-jasmine": "~4.0.0", 42 | "karma-jasmine-html-reporter": "^1.5.0", 43 | "protractor": "~7.0.0", 44 | "ts-node": "~8.3.0", 45 | "tslint": "~6.1.0", 46 | "typescript": "~4.0.2" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/about/about-data.ts: -------------------------------------------------------------------------------- 1 | export class AboutData { 2 | 3 | public id = 0; 4 | public description = ''; 5 | public deleted = false; 6 | 7 | constructor(id: number, description: string, deleted: boolean) { 8 | 9 | this.id = id; 10 | this.description = description; 11 | this.deleted = deleted; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/about/about.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Selected Item: {{model.id}}

4 |
5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 | Description is required 14 |
15 |
16 | 17 | 18 | 19 | 20 |
21 |
22 |
23 | 24 |
25 | 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 46 | 47 | 48 |
IdDescription
{{aboutItem.id}}{{aboutItem.description}} 41 | 42 | 44 | 45 |
49 | 50 |
51 | 52 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/about/about.component.ts: -------------------------------------------------------------------------------- 1 | 2 | import {distinctUntilChanged, debounceTime} from 'rxjs/operators'; 3 | import { Component, OnInit } from '@angular/core'; 4 | import { AboutData } from './about-data'; 5 | import { CommandService } from '../services/command-service'; 6 | import { CommandDto } from '../services/command-dto'; 7 | import { AboutDataService } from '../services/about-data-service'; 8 | 9 | import { Observable , Subject } from 'rxjs'; 10 | 11 | 12 | @Component({ 13 | selector: 'app-about-component', 14 | templateUrl: 'about.component.html' 15 | }) 16 | 17 | export class AboutComponent implements OnInit { 18 | 19 | public message = ''; 20 | public model: AboutData = { id: 0, description: '', deleted: false }; 21 | public submitted = false; 22 | public active = false; 23 | public AboutDataItems: AboutData[] = []; 24 | 25 | private deboucedInput: Observable | undefined; 26 | private keyDownEvents = new Subject(); 27 | 28 | constructor(private _commandService: CommandService, private _aboutDataService: AboutDataService) { 29 | this.message = 'Hello from About'; 30 | this._commandService.OnUndoRedo.subscribe((item: any) => this.OnUndoRedoRecieved(item)); 31 | } 32 | 33 | ngOnInit() { 34 | this.model = new AboutData(0, 'description', false); 35 | this.submitted = false; 36 | this.active = true; 37 | this.GetAboutDataItems(); 38 | 39 | this.deboucedInput = this.keyDownEvents; 40 | this.deboucedInput.pipe( 41 | debounceTime(1000), 42 | distinctUntilChanged()) 43 | .subscribe(() => { 44 | this.onSubmit(); 45 | }); 46 | } 47 | 48 | public GetAboutDataItems() { 49 | console.log('AboutComponent starting...'); 50 | this._aboutDataService.GetAll() 51 | .subscribe((data) => { 52 | this.AboutDataItems = data; 53 | }, 54 | error => console.log(error), 55 | () => { 56 | console.log('AboutDataService:GetAll completed'); 57 | } 58 | ); 59 | } 60 | 61 | public Edit(aboutItem: AboutData) { 62 | this.model.description = aboutItem.description; 63 | this.model.id = aboutItem.id; 64 | } 65 | 66 | public Delete(aboutItem: AboutData) { 67 | const myCommand = new CommandDto('DELETE', 'ABOUT', aboutItem, 'about'); 68 | 69 | console.log(myCommand); 70 | this._commandService.Execute(myCommand) 71 | .subscribe( 72 | () => this.GetAboutDataItems(), 73 | error => console.log(error), 74 | () => { 75 | if (this.model.id === aboutItem.id) { 76 | this.newAboutData(); 77 | } 78 | } 79 | ); 80 | } 81 | 82 | public createCommand(event: any) { 83 | this.keyDownEvents.next(this.model.description); 84 | } 85 | 86 | // TODO remove the get All request and update the list using the return item 87 | public onSubmit() { 88 | if (this.model.description !== '') { 89 | this.submitted = true; 90 | 91 | const myCommand = new CommandDto('ADD', 'ABOUT', this.model, 'about'); 92 | 93 | if (this.model.id > 0) { 94 | myCommand.commandType = 'UPDATE'; 95 | } 96 | 97 | console.log(myCommand); 98 | this._commandService.Execute(myCommand) 99 | .subscribe( 100 | data => { 101 | this.model.id = data.payload.Id; 102 | this.GetAboutDataItems(); 103 | }, 104 | error => console.log(error), 105 | () => console.log('Command executed') 106 | ); 107 | } 108 | } 109 | 110 | public newAboutData() { 111 | this.model = new AboutData(0, 'add a new description', false); 112 | this.active = false; 113 | setTimeout(() => this.active = true, 0); 114 | } 115 | 116 | private OnUndoRedoRecieved(payloadType: any) { 117 | if (payloadType === 'ABOUT') { 118 | this.GetAboutDataItems(); 119 | // this.newAboutData(); 120 | console.log('OnUndoRedoRecieved About'); 121 | console.log(payloadType); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 32 | 33 | 34 | 35 | 41 |
42 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | } 4 | 5 | .starter-template { 6 | padding: 40px 15px; 7 | text-align: center; 8 | } 9 | 10 | .navigationLinkButton:hover { 11 | cursor: pointer; 12 | } 13 | 14 | a { 15 | color: #03A9F4; 16 | } -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { CommandService } from './services/command-service'; 4 | import { CommandDto } from './services/command-dto'; 5 | 6 | @Component({ 7 | selector: 'app-root', 8 | templateUrl: './app.component.html', 9 | styleUrls: ['./app.component.scss'], 10 | }) 11 | 12 | export class AppComponent { 13 | 14 | constructor(private router: Router, private _commandService: CommandService) { 15 | } 16 | 17 | public Undo() { 18 | let resultCommand: CommandDto; 19 | 20 | this._commandService.Undo() 21 | .subscribe( 22 | data => resultCommand = data, 23 | error => console.log(error), 24 | () => { 25 | this._commandService.UndoRedoUpdate(resultCommand.payloadType); 26 | this.router.navigate(['/' + resultCommand.actualClientRoute]); 27 | } 28 | ); 29 | } 30 | 31 | public Redo() { 32 | let resultCommand: CommandDto; 33 | 34 | this._commandService.Redo() 35 | .subscribe( 36 | data => resultCommand = data, 37 | error => console.log(error), 38 | () => { 39 | this._commandService.UndoRedoUpdate(resultCommand.payloadType); 40 | this.router.navigate(['/' + resultCommand.actualClientRoute]); 41 | } 42 | ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/app.constants.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | @Injectable() 4 | export class Configuration { 5 | public Server = 'https://localhost:44382/'; 6 | } 7 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { BrowserModule } from '@angular/platform-browser'; 5 | import { AppComponent } from './app.component'; 6 | import { Configuration } from './app.constants'; 7 | import { routing } from './app.routes'; 8 | 9 | import { HomeComponent } from './home/home.component'; 10 | import { AboutComponent } from './about/about.component'; 11 | import { HttpRequestsComponent } from './httprequests/httprequests.component'; 12 | import { CommandsComponent } from './commands/commands.component'; 13 | 14 | import { CommandService } from './services/command-service'; 15 | import { AboutDataService } from './services/about-data-service'; 16 | import { HomeDataService } from './services/home-data-service'; 17 | import { HttpClientModule } from '@angular/common/http'; 18 | 19 | @NgModule({ 20 | imports: [ 21 | BrowserModule, 22 | CommonModule, 23 | FormsModule, 24 | HttpClientModule, 25 | routing 26 | ], 27 | declarations: [ 28 | AppComponent, 29 | AboutComponent, 30 | HomeComponent, 31 | HttpRequestsComponent, 32 | CommandsComponent 33 | ], 34 | providers: [ 35 | CommandService, 36 | AboutDataService, 37 | HomeDataService, 38 | Configuration 39 | ], 40 | bootstrap: [AppComponent], 41 | }) 42 | 43 | export class AppModule { } 44 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/app.routes.ts: -------------------------------------------------------------------------------- 1 | import { Routes, RouterModule } from '@angular/router'; 2 | 3 | import { HomeComponent } from './home/home.component'; 4 | import { AboutComponent } from './about/about.component'; 5 | import { HttpRequestsComponent } from './httprequests/httprequests.component'; 6 | import { CommandsComponent } from './commands/commands.component'; 7 | 8 | const appRoutes: Routes = [ 9 | { path: '', component: HomeComponent }, 10 | { path: 'home', component: HomeComponent }, 11 | { path: 'about', component: AboutComponent }, 12 | { path: 'httprequests', component: HttpRequestsComponent }, 13 | { path: 'commands', component: CommandsComponent } 14 | ]; 15 | 16 | export const routing = RouterModule.forRoot(appRoutes); 17 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/commands/commands.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
IdActualClientRouteCommandTypePayloadPayloadType
{{commands.id}}{{commands.actualClientRoute}}{{commands.commandType}}{{commands.payload}}{{commands.payloadType}}
25 | 26 |
27 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/commands/commands.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { CommandService } from '../services/command-service'; 3 | 4 | @Component({ 5 | selector: 'app-commands-component', 6 | templateUrl: 'commands.component.html' 7 | }) 8 | 9 | export class CommandsComponent implements OnInit { 10 | 11 | public message: string; 12 | public Commands: any[] = []; 13 | 14 | constructor(private _commandService: CommandService) { 15 | this.message = 'Hello from CommandsComponent constructor'; 16 | } 17 | 18 | ngOnInit() { 19 | this.GetCommands(); 20 | } 21 | 22 | public GetCommands() { 23 | this._commandService.GetAll() 24 | .subscribe((data) => { 25 | this.Commands = data; 26 | }, 27 | error => console.log(error), 28 | () => { 29 | console.log('CommandsService:GetAll completed'); 30 | } 31 | ); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/home/home-data.ts: -------------------------------------------------------------------------------- 1 | export class HomeData { 2 | 3 | public id = 0; 4 | public name = ''; 5 | public deleted = false; 6 | 7 | constructor(id: number, name: string, deleted: boolean) { 8 | 9 | this.id = id; 10 | this.name = name; 11 | this.deleted = deleted; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/home/home.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Selected Item: {{model.id}}

4 |
5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 | Name is required 14 |
15 |
16 | 17 | 18 | 19 |
20 |
21 |
22 | 23 |
24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 46 | 47 | 48 |
IdName
{{homeItem.id}}{{homeItem.name}} 41 | 42 | 44 | 45 |
49 | 50 |
51 | 52 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { HomeData } from './home-data'; 3 | import { CommandService } from '../services/command-service'; 4 | import { CommandDto } from '../services/command-dto'; 5 | import { HomeDataService } from '../services/home-data-service'; 6 | 7 | import { distinctUntilChanged, debounceTime } from 'rxjs/operators'; 8 | import { Observable , Subject } from 'rxjs'; 9 | 10 | @Component({ 11 | selector: 'app-home-component', 12 | templateUrl: 'home.component.html' 13 | }) 14 | 15 | export class HomeComponent implements OnInit { 16 | 17 | public message: string; 18 | public model: HomeData = { id: 0, name: '', deleted: false }; 19 | public submitted = false; 20 | public active = false; 21 | public HomeDataItems: HomeData[] = []; 22 | 23 | private deboucedInput: Observable | undefined; 24 | private keyDownEvents = new Subject(); 25 | 26 | constructor(private _commandService: CommandService, private _homeDataService: HomeDataService) { 27 | this.message = 'Hello from Home'; 28 | this._commandService.OnUndoRedo.subscribe((item: any) => this.OnUndoRedoRecieved(item)); 29 | } 30 | 31 | ngOnInit() { 32 | this.model = new HomeData(0, 'name', false); 33 | this.submitted = false; 34 | this.active = true; 35 | this.GetHomeDataItems(); 36 | 37 | this.deboucedInput = this.keyDownEvents; 38 | this.deboucedInput.pipe( 39 | debounceTime(1000), 40 | distinctUntilChanged()) 41 | .subscribe(() => { 42 | this.onSubmit(); 43 | }); 44 | } 45 | 46 | public GetHomeDataItems() { 47 | console.log('HomeComponent starting...'); 48 | this._homeDataService.GetAll() 49 | .subscribe((data) => { 50 | this.HomeDataItems = data; 51 | }, 52 | error => console.log(error), 53 | () => { 54 | console.log('HomeDataService:GetAll completed'); 55 | } 56 | ); 57 | } 58 | 59 | public Edit(aboutItem: HomeData) { 60 | this.model.name = aboutItem.name; 61 | this.model.id = aboutItem.id; 62 | } 63 | 64 | // TODO remove the get All request and update the list using the return item 65 | public Delete(homeItem: HomeData) { 66 | const myCommand = new CommandDto('DELETE', 'HOME', homeItem, 'home'); 67 | 68 | console.log(myCommand); 69 | this._commandService.Execute(myCommand) 70 | .subscribe( 71 | () => this.GetHomeDataItems(), 72 | error => console.log(error), 73 | () => { 74 | if (this.model.id === homeItem.id) { 75 | this.newHomeData(); 76 | } 77 | } 78 | ); 79 | } 80 | 81 | public createCommand(event: any) { 82 | this.keyDownEvents.next(this.model.name); 83 | } 84 | 85 | public onSubmit() { 86 | if (this.model.name !== '') { 87 | this.submitted = true; 88 | const myCommand = new CommandDto('ADD', 'HOME', this.model, 'home'); 89 | 90 | if (this.model.id > 0) { 91 | myCommand.commandType = 'UPDATE'; 92 | } 93 | 94 | console.log(myCommand); 95 | this._commandService.Execute(myCommand) 96 | .subscribe( 97 | data => { 98 | this.model.id = data.payload.Id; 99 | this.GetHomeDataItems(); 100 | }, 101 | error => console.log(error), 102 | () => console.log('Command executed') 103 | ); 104 | } 105 | } 106 | 107 | public newHomeData() { 108 | this.model = new HomeData(0, 'add a new name', false); 109 | this.active = false; 110 | setTimeout(() => this.active = true, 0); 111 | } 112 | 113 | private OnUndoRedoRecieved(payloadType: any) { 114 | if (payloadType === 'HOME') { 115 | this.GetHomeDataItems(); 116 | // this.newHomeData(); 117 | console.log('OnUndoRedoRecieved Home'); 118 | console.log(payloadType); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/httprequests/httprequests.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 70 |
71 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/httprequests/httprequests.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-httprequests-component', 5 | templateUrl: 'httprequests.component.html' 6 | }) 7 | 8 | export class HttpRequestsComponent { 9 | 10 | public message = ''; 11 | public values: any[] = []; 12 | 13 | constructor() { 14 | this.message = 'Hello from HttpRequestsComponent constructor'; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/services/about-data-service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { Observable } from 'rxjs'; 4 | 5 | import { Configuration } from '../app.constants'; 6 | 7 | @Injectable() 8 | export class AboutDataService { 9 | 10 | private actionUrl: string; 11 | private headers: HttpHeaders; 12 | 13 | constructor(private http: HttpClient, configuration: Configuration) { 14 | 15 | this.actionUrl = `${configuration.Server}api/about/`; 16 | 17 | this.headers = new HttpHeaders(); 18 | this.headers = this.headers.set('Content-Type', 'application/json'); 19 | this.headers = this.headers.set('Accept', 'application/json'); 20 | } 21 | 22 | public GetAll = (): Observable => { 23 | return this.http.get(this.actionUrl, { headers: this.headers }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/services/command-dto.ts: -------------------------------------------------------------------------------- 1 | export class CommandDto { 2 | 3 | public commandType: string; 4 | public payloadType: string; 5 | public payload: any; 6 | public actualClientRoute: string; 7 | 8 | constructor(commandType: string, payloadType: string, payload: any, actualClientRoute: string) { 9 | 10 | this.commandType = commandType; 11 | this.payloadType = payloadType; 12 | this.payload = payload; 13 | this.actualClientRoute = actualClientRoute; 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/services/command-service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 2 | import { Injectable, EventEmitter, Output } from '@angular/core'; 3 | import { Observable } from 'rxjs'; 4 | 5 | import { Configuration } from '../app.constants'; 6 | import { CommandDto } from './command-dto'; 7 | 8 | @Injectable() 9 | export class CommandService { 10 | 11 | @Output() OnUndoRedo = new EventEmitter(); 12 | 13 | private actionUrl: string; 14 | private headers: HttpHeaders; 15 | 16 | constructor(private http: HttpClient, configuration: Configuration) { 17 | 18 | this.actionUrl = `${configuration.Server}api/command/`; 19 | 20 | this.headers = new HttpHeaders(); 21 | this.headers = this.headers.set('Content-Type', 'application/json'); 22 | this.headers = this.headers.set('Accept', 'application/json'); 23 | } 24 | 25 | public Execute = (command: CommandDto): Observable => { 26 | const url = `${this.actionUrl}execute`; 27 | return this.http.post(url, command, { headers: this.headers }); 28 | } 29 | 30 | public Undo = (): Observable => { 31 | const url = `${this.actionUrl}undo`; 32 | return this.http.post(url, '', { headers: this.headers }); 33 | } 34 | 35 | public Redo = (): Observable => { 36 | const url = `${this.actionUrl}redo`; 37 | return this.http.post(url, '', { headers: this.headers }); 38 | } 39 | 40 | public GetAll = (): Observable => { 41 | return this.http.get(this.actionUrl, { headers: this.headers }); 42 | } 43 | 44 | public UndoRedoUpdate = (payloadType: string) => { 45 | this.OnUndoRedo.emit(payloadType); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/app/services/home-data-service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { Observable } from 'rxjs'; 4 | 5 | import { Configuration } from '../app.constants'; 6 | 7 | @Injectable() 8 | export class HomeDataService { 9 | 10 | private actionUrl: string; 11 | private headers: HttpHeaders; 12 | 13 | constructor(private http: HttpClient, configuration: Configuration) { 14 | 15 | this.actionUrl = `${configuration.Server}api/home/`; 16 | 17 | this.headers = new HttpHeaders(); 18 | this.headers = this.headers.set('Content-Type', 'application/json'); 19 | this.headers = this.headers.set('Accept', 'application/json'); 20 | } 21 | 22 | public GetAll = (): Observable => { 23 | return this.http.get(this.actionUrl, { headers: this.headers }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienbod/AngularAutoSaveCommands/4bfd8259b50bfb2f5cf7016c2cf2f04351a02bcf/AutoSaveCommandsAngular/src/assets/.gitkeep -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienbod/AngularAutoSaveCommands/4bfd8259b50bfb2f5cf7016c2cf2f04351a02bcf/AutoSaveCommandsAngular/src/favicon.ico -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AutoSaveCommandsAngular 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | @import '~bootstrap/dist/css/bootstrap.css'; 3 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitReturns": true, 10 | "noFallthroughCasesInSwitch": true, 11 | "sourceMap": true, 12 | "declaration": false, 13 | "downlevelIteration": true, 14 | "experimentalDecorators": true, 15 | "moduleResolution": "node", 16 | "importHelpers": true, 17 | "target": "es2015", 18 | "module": "es2020", 19 | "lib": [ 20 | "es2018", 21 | "dom" 22 | ] 23 | }, 24 | "angularCompilerOptions": { 25 | "strictInjectionParameters": true, 26 | "strictInputAccessModifiers": true, 27 | "strictTemplates": true 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /AutoSaveCommandsAngular/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rulesDirectory": [ 4 | "codelyzer" 5 | ], 6 | "rules": { 7 | "align": { 8 | "options": [ 9 | "parameters", 10 | "statements" 11 | ] 12 | }, 13 | "array-type": false, 14 | "arrow-return-shorthand": true, 15 | "curly": true, 16 | "deprecation": { 17 | "severity": "warning" 18 | }, 19 | "eofline": true, 20 | "import-blacklist": [ 21 | true, 22 | "rxjs/Rx" 23 | ], 24 | "import-spacing": true, 25 | "indent": { 26 | "options": [ 27 | "spaces" 28 | ] 29 | }, 30 | "max-classes-per-file": false, 31 | "max-line-length": [ 32 | true, 33 | 140 34 | ], 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-console": [ 47 | true, 48 | "debug", 49 | "info", 50 | "time", 51 | "timeEnd", 52 | "trace" 53 | ], 54 | "no-empty": false, 55 | "no-inferrable-types": [ 56 | true, 57 | "ignore-params" 58 | ], 59 | "no-non-null-assertion": true, 60 | "no-redundant-jsdoc": true, 61 | "no-switch-case-fall-through": true, 62 | "no-var-requires": false, 63 | "object-literal-key-quotes": [ 64 | true, 65 | "as-needed" 66 | ], 67 | "quotemark": [ 68 | true, 69 | "single" 70 | ], 71 | "semicolon": { 72 | "options": [ 73 | "always" 74 | ] 75 | }, 76 | "space-before-function-paren": { 77 | "options": { 78 | "anonymous": "never", 79 | "asyncArrow": "always", 80 | "constructor": "never", 81 | "method": "never", 82 | "named": "never" 83 | } 84 | }, 85 | "typedef": [ 86 | true, 87 | "call-signature" 88 | ], 89 | "typedef-whitespace": { 90 | "options": [ 91 | { 92 | "call-signature": "nospace", 93 | "index-signature": "nospace", 94 | "parameter": "nospace", 95 | "property-declaration": "nospace", 96 | "variable-declaration": "nospace" 97 | }, 98 | { 99 | "call-signature": "onespace", 100 | "index-signature": "onespace", 101 | "parameter": "onespace", 102 | "property-declaration": "onespace", 103 | "variable-declaration": "onespace" 104 | } 105 | ] 106 | }, 107 | "variable-name": { 108 | "options": [ 109 | "ban-keywords", 110 | "check-format", 111 | "allow-pascal-case" 112 | ] 113 | }, 114 | "whitespace": { 115 | "options": [ 116 | "check-branch", 117 | "check-decl", 118 | "check-operator", 119 | "check-separator", 120 | "check-type", 121 | "check-typecast" 122 | ] 123 | }, 124 | "component-class-suffix": true, 125 | "contextual-lifecycle": true, 126 | "directive-class-suffix": true, 127 | "no-conflicting-lifecycle": true, 128 | "no-host-metadata-property": true, 129 | "no-input-rename": true, 130 | "no-inputs-metadata-property": true, 131 | "no-output-native": true, 132 | "no-output-on-prefix": true, 133 | "no-output-rename": true, 134 | "no-outputs-metadata-property": true, 135 | "template-banana-in-box": true, 136 | "template-no-negated-async": true, 137 | "use-lifecycle-interface": true, 138 | "use-pipe-transform-interface": true, 139 | "directive-selector": [ 140 | true, 141 | "attribute", 142 | "app", 143 | "camelCase" 144 | ], 145 | "component-selector": [ 146 | true, 147 | "element", 148 | "app", 149 | "kebab-case" 150 | ] 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/ActionFilters/ValidateCommandDtoFilter.cs: -------------------------------------------------------------------------------- 1 | using AutoSaveCommandsApi.Models; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.AspNetCore.Mvc.Filters; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace AutoSaveCommandsApi.ActionFilters 7 | { 8 | public class ValidateCommandDtoFilter : ActionFilterAttribute 9 | { 10 | private readonly ILogger _logger; 11 | 12 | public ValidateCommandDtoFilter(ILoggerFactory loggerFactory) 13 | { 14 | _logger = loggerFactory.CreateLogger("ValidatePayloadTypeFilter"); 15 | } 16 | 17 | public override void OnActionExecuting(ActionExecutingContext context) 18 | { 19 | var commandDto = context.ActionArguments["commandDto"] as CommandDto; 20 | if (commandDto == null) 21 | { 22 | context.HttpContext.Response.StatusCode = 400; 23 | context.Result = new ContentResult() 24 | { 25 | Content = "The body is not a CommandDto type" 26 | }; 27 | return; 28 | } 29 | 30 | _logger.LogDebug("validating CommandType"); 31 | if (!CommandTypes.AllowedTypes.Contains(commandDto.CommandType)) 32 | { 33 | context.HttpContext.Response.StatusCode = 400; 34 | context.Result = new ContentResult() 35 | { 36 | Content = "CommandTypes not allowed" 37 | }; 38 | return; 39 | } 40 | 41 | _logger.LogDebug("validating PayloadType"); 42 | if (!PayloadTypes.AllowedTypes.Contains(commandDto.PayloadType)) 43 | { 44 | context.HttpContext.Response.StatusCode = 400; 45 | context.Result = new ContentResult() 46 | { 47 | Content = "PayloadType not allowed" 48 | }; 49 | return; 50 | } 51 | 52 | base.OnActionExecuting(context); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/AutoSaveCommandsApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | runtime; build; native; contentfiles; analyzers 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Controllers/AboutController.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace AutoSaveCommandsApi.Controllers 6 | { 7 | [Route("api/[controller]")] 8 | public class AboutController : Controller 9 | { 10 | private readonly DomainModelMsSqlServerContext _context; 11 | private readonly ILoggerFactory _loggerFactory; 12 | private readonly ILogger _logger; 13 | 14 | public AboutController(DomainModelMsSqlServerContext context, ILoggerFactory loggerFactory) 15 | { 16 | _context = context; 17 | _loggerFactory = loggerFactory; 18 | _logger = loggerFactory.CreateLogger("AboutController"); 19 | } 20 | 21 | [HttpGet] 22 | public IActionResult Get() 23 | { 24 | _logger.LogDebug("Get all AboutData items called"); 25 | return Ok(_context.AboutData.Where(item => item.Deleted == false).ToList()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Controllers/CommandController.cs: -------------------------------------------------------------------------------- 1 | using AutoSaveCommandsApi.ActionFilters; 2 | using AutoSaveCommandsApi.Models; 3 | using AutoSaveCommandsApi.Providers; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace AutoSaveCommandsApi.Controllers 7 | { 8 | [Route("api/[controller]")] 9 | public class CommandController : Controller 10 | { 11 | private readonly ICommandHandler _commandHandler; 12 | public CommandController(ICommandHandler commandHandler) 13 | { 14 | _commandHandler = commandHandler; 15 | } 16 | 17 | [ServiceFilter(typeof(ValidateCommandDtoFilter))] 18 | [HttpPost] 19 | [Route("Execute")] 20 | public IActionResult Post([FromBody]CommandDto commandDto) 21 | { 22 | _commandHandler.Execute(commandDto); 23 | return Ok(commandDto); 24 | } 25 | 26 | [HttpPost] 27 | [Route("Undo")] 28 | public IActionResult Undo() 29 | { 30 | var commandDto = _commandHandler.Undo(); 31 | return Ok(commandDto); 32 | } 33 | 34 | [HttpPost] 35 | [Route("Redo")] 36 | public IActionResult Redo() 37 | { 38 | var commandDto = _commandHandler.Redo(); 39 | return Ok(commandDto); 40 | } 41 | 42 | [HttpGet] 43 | public IActionResult Get() 44 | { 45 | return Ok(_commandHandler.GetAll()); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.Extensions.Logging; 4 | 5 | namespace AutoSaveCommandsApi.Controllers 6 | { 7 | [Route("api/[controller]")] 8 | public class HomeController : Controller 9 | { 10 | private readonly DomainModelMsSqlServerContext _context; 11 | private readonly ILoggerFactory _loggerFactory; 12 | private readonly ILogger _logger; 13 | 14 | public HomeController(DomainModelMsSqlServerContext context, ILoggerFactory loggerFactory) 15 | { 16 | _context = context; 17 | _loggerFactory = loggerFactory; 18 | _logger = loggerFactory.CreateLogger("HomeController"); 19 | } 20 | 21 | [HttpGet] 22 | public IActionResult Get() 23 | { 24 | _logger.LogDebug("Get all HomeData items called"); 25 | return Ok(_context.HomeData.Where(item => item.Deleted == false).ToList()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/DomainModelMsSqlServerContext.cs: -------------------------------------------------------------------------------- 1 | using AutoSaveCommandsApi.Models; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace AutoSaveCommandsApi 5 | { 6 | // >dotnet ef migration add testMigration 7 | public class DomainModelMsSqlServerContext : DbContext 8 | { 9 | public DomainModelMsSqlServerContext(DbContextOptions options) : base(options) 10 | { } 11 | 12 | public DbSet AboutData { get; set; } 13 | 14 | public DbSet HomeData { get; set; } 15 | 16 | public DbSet CommandEntity { get; set; } 17 | 18 | protected override void OnModelCreating(ModelBuilder builder) 19 | { 20 | builder.Entity().HasKey(m => m.Id); 21 | builder.Entity().HasKey(m => m.Id); 22 | builder.Entity().HasKey(m => m.Id); 23 | 24 | base.OnModelCreating(builder); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Migrations/20180616095050_init.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using AutoSaveCommandsApi; 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 AutoSaveCommandsApi.Migrations 10 | { 11 | [DbContext(typeof(DomainModelMsSqlServerContext))] 12 | [Migration("20180616095050_init")] 13 | partial class init 14 | { 15 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 16 | { 17 | #pragma warning disable 612, 618 18 | modelBuilder 19 | .HasAnnotation("ProductVersion", "2.1.0-rtm-30799") 20 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 21 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 22 | 23 | modelBuilder.Entity("AutoSaveCommandsApi.Models.AboutData", b => 24 | { 25 | b.Property("Id") 26 | .ValueGeneratedOnAdd() 27 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 28 | 29 | b.Property("Deleted"); 30 | 31 | b.Property("Description"); 32 | 33 | b.HasKey("Id"); 34 | 35 | b.ToTable("AboutData"); 36 | }); 37 | 38 | modelBuilder.Entity("AutoSaveCommandsApi.Models.CommandEntity", b => 39 | { 40 | b.Property("Id") 41 | .ValueGeneratedOnAdd() 42 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 43 | 44 | b.Property("ActualClientRoute"); 45 | 46 | b.Property("CommandType"); 47 | 48 | b.Property("Payload"); 49 | 50 | b.Property("PayloadType"); 51 | 52 | b.HasKey("Id"); 53 | 54 | b.ToTable("CommandEntity"); 55 | }); 56 | 57 | modelBuilder.Entity("AutoSaveCommandsApi.Models.HomeData", b => 58 | { 59 | b.Property("Id") 60 | .ValueGeneratedOnAdd() 61 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 62 | 63 | b.Property("Deleted"); 64 | 65 | b.Property("Name"); 66 | 67 | b.HasKey("Id"); 68 | 69 | b.ToTable("HomeData"); 70 | }); 71 | #pragma warning restore 612, 618 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Migrations/20180616095050_init.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | namespace AutoSaveCommandsApi.Migrations 5 | { 6 | public partial class init : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "AboutData", 12 | columns: table => new 13 | { 14 | Id = table.Column(nullable: false) 15 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 16 | Description = table.Column(nullable: true), 17 | Deleted = table.Column(nullable: false) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_AboutData", x => x.Id); 22 | }); 23 | 24 | migrationBuilder.CreateTable( 25 | name: "CommandEntity", 26 | columns: table => new 27 | { 28 | Id = table.Column(nullable: false) 29 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 30 | CommandType = table.Column(nullable: true), 31 | PayloadType = table.Column(nullable: true), 32 | Payload = table.Column(nullable: true), 33 | ActualClientRoute = table.Column(nullable: true) 34 | }, 35 | constraints: table => 36 | { 37 | table.PrimaryKey("PK_CommandEntity", x => x.Id); 38 | }); 39 | 40 | migrationBuilder.CreateTable( 41 | name: "HomeData", 42 | columns: table => new 43 | { 44 | Id = table.Column(nullable: false) 45 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 46 | Name = table.Column(nullable: true), 47 | Deleted = table.Column(nullable: false) 48 | }, 49 | constraints: table => 50 | { 51 | table.PrimaryKey("PK_HomeData", x => x.Id); 52 | }); 53 | } 54 | 55 | protected override void Down(MigrationBuilder migrationBuilder) 56 | { 57 | migrationBuilder.DropTable( 58 | name: "AboutData"); 59 | 60 | migrationBuilder.DropTable( 61 | name: "CommandEntity"); 62 | 63 | migrationBuilder.DropTable( 64 | name: "HomeData"); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Migrations/DomainModelMsSqlServerContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using AutoSaveCommandsApi; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Metadata; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | 8 | namespace AutoSaveCommandsApi.Migrations 9 | { 10 | [DbContext(typeof(DomainModelMsSqlServerContext))] 11 | partial class DomainModelMsSqlServerContextModelSnapshot : ModelSnapshot 12 | { 13 | protected override void BuildModel(ModelBuilder modelBuilder) 14 | { 15 | #pragma warning disable 612, 618 16 | modelBuilder 17 | .HasAnnotation("ProductVersion", "2.1.0-rtm-30799") 18 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 19 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 20 | 21 | modelBuilder.Entity("AutoSaveCommandsApi.Models.AboutData", b => 22 | { 23 | b.Property("Id") 24 | .ValueGeneratedOnAdd() 25 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 26 | 27 | b.Property("Deleted"); 28 | 29 | b.Property("Description"); 30 | 31 | b.HasKey("Id"); 32 | 33 | b.ToTable("AboutData"); 34 | }); 35 | 36 | modelBuilder.Entity("AutoSaveCommandsApi.Models.CommandEntity", b => 37 | { 38 | b.Property("Id") 39 | .ValueGeneratedOnAdd() 40 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 41 | 42 | b.Property("ActualClientRoute"); 43 | 44 | b.Property("CommandType"); 45 | 46 | b.Property("Payload"); 47 | 48 | b.Property("PayloadType"); 49 | 50 | b.HasKey("Id"); 51 | 52 | b.ToTable("CommandEntity"); 53 | }); 54 | 55 | modelBuilder.Entity("AutoSaveCommandsApi.Models.HomeData", b => 56 | { 57 | b.Property("Id") 58 | .ValueGeneratedOnAdd() 59 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 60 | 61 | b.Property("Deleted"); 62 | 63 | b.Property("Name"); 64 | 65 | b.HasKey("Id"); 66 | 67 | b.ToTable("HomeData"); 68 | }); 69 | #pragma warning restore 612, 618 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Models/AboutData.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace AutoSaveCommandsApi.Models 5 | { 6 | public class AboutData 7 | { 8 | [Key] 9 | public long Id { get; set; } 10 | 11 | public string Description { get; set; } 12 | 13 | public bool Deleted { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Models/CommandDto.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | using System; 3 | using System.Text.Json; 4 | 5 | namespace AutoSaveCommandsApi.Models 6 | { 7 | public class CommandDto 8 | { 9 | public string CommandType { get; set; } 10 | 11 | public string PayloadType { get; set; } 12 | 13 | public JObject Payload { get; set; } 14 | 15 | public string ActualClientRoute { get; set;} 16 | 17 | } 18 | 19 | public class CommandDtoObject 20 | { 21 | public string CommandType { get; set; } 22 | 23 | public string PayloadType { get; set; } 24 | 25 | public Object Payload { get; set; } 26 | 27 | public string ActualClientRoute { get; set; } 28 | 29 | } 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Models/CommandEntity.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | using Newtonsoft.Json.Linq; 4 | 5 | namespace AutoSaveCommandsApi.Models 6 | { 7 | public class CommandEntity 8 | { 9 | [Key] 10 | public long Id { get; set; } 11 | 12 | public string CommandType { get; set; } 13 | 14 | public string PayloadType { get; set; } 15 | 16 | public string Payload { get; set; } 17 | 18 | public string ActualClientRoute { get; set;} 19 | 20 | public static CommandEntity CreateCommandEntity(CommandDto commandDto) 21 | { 22 | CommandEntity commandEntity = new CommandEntity(); 23 | commandEntity.ActualClientRoute = commandDto.ActualClientRoute; 24 | commandEntity.CommandType = commandDto.CommandType; 25 | commandEntity.PayloadType = commandDto.PayloadType; 26 | if(commandDto.Payload != null) 27 | { 28 | commandEntity.Payload = commandDto.Payload.ToString(); 29 | } 30 | 31 | return commandEntity; 32 | } 33 | 34 | public CommandDto ToCommandDto() 35 | { 36 | CommandDto commandDto = new CommandDto(); 37 | 38 | commandDto.ActualClientRoute = ActualClientRoute; 39 | commandDto.CommandType = CommandType; 40 | commandDto.PayloadType = PayloadType; 41 | if(Payload != null) 42 | { 43 | commandDto.Payload = JObject.Parse(Payload); 44 | } 45 | 46 | return commandDto; 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Models/CommandTypes.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace AutoSaveCommandsApi.Models 4 | { 5 | public static class CommandTypes 6 | { 7 | public const string ADD = "ADD"; 8 | public const string UPDATE = "UPDATE"; 9 | public const string DELETE = "DELETE"; 10 | public const string UNDO = "UNDO"; 11 | public const string REDO = "REDO"; 12 | 13 | public static List AllowedTypes = new List() { ADD, UPDATE, DELETE, UNDO, REDO }; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Models/HomeData.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace AutoSaveCommandsApi.Models 5 | { 6 | public class HomeData 7 | { 8 | [Key] 9 | public long Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public bool Deleted { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Models/PayloadTypes.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace AutoSaveCommandsApi.Models 4 | { 5 | public static class PayloadTypes 6 | { 7 | public const string HOME = "HOME"; 8 | public const string ABOUT = "ABOUT"; 9 | public const string NONE = "NONE"; 10 | 11 | public static List AllowedTypes = new List() { HOME, ABOUT, NONE }; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.Hosting; 4 | using Microsoft.Extensions.Logging; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace AutoSaveCommandsApi 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 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "https://localhost:44382/", 7 | "sslPort": 44382 8 | } 9 | }, 10 | "$schema": "http://json.schemastore.org/launchsettings.json", 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "AutoSaveCommandsApi": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "swagger", 24 | "environmentVariables": { 25 | "ASPNETCORE_ENVIRONMENT": "Development" 26 | }, 27 | "dotnetRunMessages": "true", 28 | "applicationUrl": "https://localhost:5001;http://localhost:5000" 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/CommandDataAccessProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using AutoSaveCommandsApi.Models; 3 | using Microsoft.Extensions.Logging; 4 | using System.Linq; 5 | 6 | namespace AutoSaveCommandsApi.Providers 7 | { 8 | public class CommandDataAccessProvider : ICommandDataAccessProvider 9 | { 10 | public static long ActiveCommand = 0; 11 | private readonly DomainModelMsSqlServerContext _context; 12 | private readonly ILogger _logger; 13 | 14 | public CommandDataAccessProvider(DomainModelMsSqlServerContext context, ILoggerFactory loggerFactory) 15 | { 16 | _context = context; 17 | _logger = loggerFactory.CreateLogger("DataAccessMsSqlServerProvider"); 18 | } 19 | 20 | public void AddCommand(CommandEntity command) 21 | { 22 | _context.CommandEntity.Add(command); 23 | _context.Add(command); 24 | } 25 | 26 | public void Save() 27 | { 28 | _context.SaveChanges(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/CommandHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using AutoSaveCommandsApi.Models; 6 | using AutoSaveCommandsApi.Providers.Commands; 7 | using Microsoft.Extensions.Logging; 8 | 9 | namespace AutoSaveCommandsApi.Providers 10 | { 11 | public class CommandHandler : ICommandHandler 12 | { 13 | private readonly ICommandDataAccessProvider _commandDataAccessProvider; 14 | private readonly DomainModelMsSqlServerContext _context; 15 | private readonly ILoggerFactory _loggerFactory; 16 | private readonly ILogger _logger; 17 | 18 | // TODO remove these and used persistent stacks 19 | private static ConcurrentStack _undocommands = new ConcurrentStack(); 20 | private static ConcurrentStack _redocommands = new ConcurrentStack(); 21 | 22 | public CommandHandler(ICommandDataAccessProvider commandDataAccessProvider, DomainModelMsSqlServerContext context, ILoggerFactory loggerFactory) 23 | { 24 | _commandDataAccessProvider = commandDataAccessProvider; 25 | _context = context; 26 | _loggerFactory = loggerFactory; 27 | _logger = loggerFactory.CreateLogger("CommandHandler"); 28 | } 29 | 30 | public void Execute(CommandDto commandDto) 31 | { 32 | if (commandDto.PayloadType == PayloadTypes.ABOUT) 33 | { 34 | ExecuteAboutDataCommand(commandDto); 35 | return; 36 | } 37 | 38 | if (commandDto.PayloadType == PayloadTypes.HOME) 39 | { 40 | ExecuteHomeDataCommand(commandDto); 41 | return; 42 | } 43 | 44 | if (commandDto.PayloadType == PayloadTypes.NONE) 45 | { 46 | ExecuteNoDataCommand(commandDto); 47 | return; 48 | } 49 | } 50 | 51 | // TODO add return object for UI 52 | public CommandDto Undo() 53 | { 54 | var commandDto = new CommandDto(); 55 | commandDto.CommandType = CommandTypes.UNDO; 56 | commandDto.PayloadType = PayloadTypes.NONE; 57 | commandDto.ActualClientRoute = "NONE"; 58 | 59 | if (_undocommands.Count > 0) 60 | { 61 | ICommand command; 62 | if (_undocommands.TryPop(out command)) 63 | { 64 | _redocommands.Push(command); 65 | command.UnExecute(_context); 66 | commandDto.Payload = command.ActualCommandDtoForNewState(CommandTypes.UNDO).Payload; 67 | _commandDataAccessProvider.AddCommand(CommandEntity.CreateCommandEntity(commandDto)); 68 | _commandDataAccessProvider.Save(); 69 | return command.ActualCommandDtoForNewState(CommandTypes.UNDO); 70 | } 71 | } 72 | 73 | return commandDto; 74 | } 75 | 76 | // TODO add return object for UI 77 | public CommandDto Redo() 78 | { 79 | var commandDto = new CommandDto(); 80 | commandDto.CommandType = CommandTypes.REDO; 81 | commandDto.PayloadType = PayloadTypes.NONE; 82 | commandDto.ActualClientRoute = "NONE"; 83 | 84 | if (_redocommands.Count > 0) 85 | { 86 | ICommand command; 87 | if(_redocommands.TryPop(out command)) 88 | { 89 | _undocommands.Push(command); 90 | command.Execute(_context); 91 | commandDto.Payload = command.ActualCommandDtoForNewState(CommandTypes.REDO).Payload; 92 | _commandDataAccessProvider.AddCommand(CommandEntity.CreateCommandEntity(commandDto)); 93 | _commandDataAccessProvider.Save(); 94 | return command.ActualCommandDtoForNewState(CommandTypes.REDO); 95 | } 96 | } 97 | 98 | return commandDto; 99 | } 100 | 101 | private void ExecuteHomeDataCommand(CommandDto commandDto) 102 | { 103 | if (commandDto.CommandType == CommandTypes.ADD) 104 | { 105 | ICommandAdd command = new AddHomeDataCommand(_loggerFactory, commandDto); 106 | command.Execute(_context); 107 | _commandDataAccessProvider.AddCommand(CommandEntity.CreateCommandEntity(commandDto)); 108 | _commandDataAccessProvider.Save(); 109 | command.UpdateIdforNewItems(); 110 | _undocommands.Push(command); 111 | } 112 | 113 | if (commandDto.CommandType == CommandTypes.UPDATE) 114 | { 115 | ICommand command = new UpdateHomeDataCommand(_loggerFactory, commandDto); 116 | command.Execute(_context); 117 | _commandDataAccessProvider.AddCommand(CommandEntity.CreateCommandEntity(commandDto)); 118 | _commandDataAccessProvider.Save(); 119 | _undocommands.Push(command); 120 | } 121 | 122 | if (commandDto.CommandType == CommandTypes.DELETE) 123 | { 124 | ICommand command = new DeleteHomeDataCommand(_loggerFactory, commandDto); 125 | command.Execute(_context); 126 | _commandDataAccessProvider.AddCommand(CommandEntity.CreateCommandEntity(commandDto)); 127 | _commandDataAccessProvider.Save(); 128 | _undocommands.Push(command); 129 | } 130 | } 131 | 132 | 133 | private void ExecuteAboutDataCommand(CommandDto commandDto) 134 | { 135 | if(commandDto.CommandType == CommandTypes.ADD) 136 | { 137 | ICommandAdd command = new AddAboutDataCommand(_loggerFactory, commandDto); 138 | command.Execute(_context); 139 | _commandDataAccessProvider.AddCommand(CommandEntity.CreateCommandEntity(commandDto)); 140 | _commandDataAccessProvider.Save(); 141 | command.UpdateIdforNewItems(); 142 | _undocommands.Push(command); 143 | } 144 | 145 | if (commandDto.CommandType == CommandTypes.UPDATE) 146 | { 147 | ICommand command = new UpdateAboutDataCommand(_loggerFactory, commandDto); 148 | command.Execute(_context); 149 | _commandDataAccessProvider.AddCommand(CommandEntity.CreateCommandEntity(commandDto)); 150 | _commandDataAccessProvider.Save(); 151 | _undocommands.Push(command); 152 | } 153 | 154 | if (commandDto.CommandType == CommandTypes.DELETE) 155 | { 156 | ICommand command = new DeleteAboutDataCommand(_loggerFactory, commandDto); 157 | command.Execute(_context); 158 | _commandDataAccessProvider.AddCommand(CommandEntity.CreateCommandEntity(commandDto)); 159 | _commandDataAccessProvider.Save(); 160 | _undocommands.Push(command); 161 | } 162 | } 163 | 164 | private void ExecuteNoDataCommand(CommandDto commandDto) 165 | { 166 | _commandDataAccessProvider.AddCommand(CommandEntity.CreateCommandEntity(commandDto)); 167 | _commandDataAccessProvider.Save(); 168 | } 169 | 170 | public List GetAll() 171 | { 172 | return _context.CommandEntity.ToList(); 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/Commands/AddAboutDataCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using AutoSaveCommandsApi.Models; 4 | using Microsoft.Extensions.Logging; 5 | using Newtonsoft.Json.Linq; 6 | 7 | namespace AutoSaveCommandsApi.Providers.Commands 8 | { 9 | public class AddAboutDataCommand : ICommandAdd 10 | { 11 | private readonly ILogger _logger; 12 | private readonly CommandDto _commandDto; 13 | private AboutData _aboutData; 14 | 15 | public AddAboutDataCommand(ILoggerFactory loggerFactory, CommandDto commandDto) 16 | { 17 | _logger = loggerFactory.CreateLogger("AddAboutDataCommand"); 18 | _commandDto = commandDto; 19 | } 20 | 21 | public void Execute(DomainModelMsSqlServerContext context) 22 | { 23 | _aboutData = _commandDto.Payload.ToObject(); 24 | if(_aboutData.Id > 0) 25 | { 26 | _aboutData.Deleted = false; 27 | context.AboutData.Update(_aboutData); 28 | } 29 | else 30 | { 31 | context.AboutData.Add(_aboutData); 32 | } 33 | 34 | _logger.LogDebug("Executed"); 35 | } 36 | 37 | public void UnExecute(DomainModelMsSqlServerContext context) 38 | { 39 | _aboutData = _commandDto.Payload.ToObject(); 40 | _aboutData.Deleted = true; 41 | var entity = context.AboutData.First(t => t.Id == _aboutData.Id); 42 | entity.Deleted = true; 43 | _logger.LogDebug("Unexecuted"); 44 | } 45 | 46 | public void UpdateIdforNewItems() 47 | { 48 | _commandDto.Payload = JObject.FromObject(_aboutData); 49 | } 50 | 51 | public CommandDto ActualCommandDtoForNewState(string commandType) 52 | { 53 | var aboutData = _commandDto.Payload.ToObject(); 54 | var commandDto = new CommandDto(); 55 | commandDto.ActualClientRoute = _commandDto.ActualClientRoute; 56 | commandDto.CommandType = _commandDto.CommandType; 57 | commandDto.PayloadType = _commandDto.PayloadType; 58 | aboutData.Deleted = _aboutData.Deleted; 59 | 60 | commandDto.Payload = JObject.FromObject(aboutData); 61 | return commandDto; 62 | 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/Commands/AddHomeDataCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using AutoSaveCommandsApi.Models; 4 | using Microsoft.Extensions.Logging; 5 | using Newtonsoft.Json.Linq; 6 | 7 | namespace AutoSaveCommandsApi.Providers.Commands 8 | { 9 | public class AddHomeDataCommand : ICommandAdd 10 | { 11 | private readonly ILogger _logger; 12 | private readonly CommandDto _commandDto; 13 | 14 | private HomeData _homeData; 15 | 16 | public AddHomeDataCommand(ILoggerFactory loggerFactory, CommandDto commandDto) 17 | { 18 | _logger = loggerFactory.CreateLogger("AddHomeDataCommand"); 19 | _commandDto = commandDto; 20 | } 21 | 22 | public void Execute(DomainModelMsSqlServerContext context) 23 | { 24 | _homeData = _commandDto.Payload.ToObject(); 25 | if (_homeData.Id > 0) 26 | { 27 | _homeData.Deleted = false; 28 | context.HomeData.Update(_homeData); 29 | } 30 | else 31 | { 32 | context.HomeData.Add(_homeData); 33 | } 34 | 35 | _logger.LogDebug("Executed"); 36 | } 37 | 38 | public void UnExecute(DomainModelMsSqlServerContext context) 39 | { 40 | _homeData = _commandDto.Payload.ToObject(); 41 | var entity = context.HomeData.First(t => t.Id == _homeData.Id); 42 | entity.Deleted = true; 43 | _logger.LogDebug("Unexecuted"); 44 | } 45 | 46 | public void UpdateIdforNewItems() 47 | { 48 | _commandDto.Payload = JObject.FromObject(_homeData); 49 | } 50 | 51 | public CommandDto ActualCommandDtoForNewState(string commandType) 52 | { 53 | return _commandDto; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/Commands/DeleteAboutDataCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using AutoSaveCommandsApi.Models; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace AutoSaveCommandsApi.Providers.Commands 7 | { 8 | public class DeleteAboutDataCommand : ICommand 9 | { 10 | private readonly ILogger _logger; 11 | private readonly CommandDto _commandDto; 12 | 13 | public DeleteAboutDataCommand(ILoggerFactory loggerFactory, CommandDto commandDto) 14 | { 15 | _logger = loggerFactory.CreateLogger("DeleteAboutDataCommand"); 16 | _commandDto = commandDto; 17 | } 18 | 19 | public void Execute(DomainModelMsSqlServerContext context) 20 | { 21 | var aboutData = _commandDto.Payload.ToObject(); 22 | var entity = context.AboutData.First(t => t.Id == aboutData.Id); 23 | entity.Deleted = true; 24 | _logger.LogDebug("Executed"); 25 | } 26 | 27 | public void UnExecute(DomainModelMsSqlServerContext context) 28 | { 29 | var aboutData = _commandDto.Payload.ToObject(); 30 | var entity = context.AboutData.First(t => t.Id == aboutData.Id); 31 | entity.Deleted = false; 32 | _logger.LogDebug("Unexecuted"); 33 | } 34 | 35 | public CommandDto ActualCommandDtoForNewState(string commandType) 36 | { 37 | return _commandDto; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/Commands/DeleteHomeDataCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using AutoSaveCommandsApi.Models; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace AutoSaveCommandsApi.Providers.Commands 7 | { 8 | public class DeleteHomeDataCommand : ICommand 9 | { 10 | private readonly ILogger _logger; 11 | private readonly CommandDto _commandDto; 12 | 13 | public DeleteHomeDataCommand(ILoggerFactory loggerFactory, CommandDto commandDto) 14 | { 15 | _logger = loggerFactory.CreateLogger("DeleteHomeDataCommand"); 16 | _commandDto = commandDto; 17 | } 18 | 19 | public void Execute(DomainModelMsSqlServerContext context) 20 | { 21 | var homeData = _commandDto.Payload.ToObject(); 22 | var entity = context.HomeData.First(t => t.Id == homeData.Id); 23 | entity.Deleted = true; 24 | _logger.LogDebug("Executed"); 25 | } 26 | 27 | public void UnExecute(DomainModelMsSqlServerContext context) 28 | { 29 | var homeData = _commandDto.Payload.ToObject(); 30 | var entity = context.HomeData.First(t => t.Id == homeData.Id); 31 | entity.Deleted = false; 32 | _logger.LogDebug("Unexecuted"); 33 | } 34 | 35 | public CommandDto ActualCommandDtoForNewState(string commandType) 36 | { 37 | return _commandDto; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/Commands/ICommand.cs: -------------------------------------------------------------------------------- 1 | using AutoSaveCommandsApi.Models; 2 | 3 | namespace AutoSaveCommandsApi.Providers.Commands 4 | { 5 | public interface ICommand 6 | { 7 | void Execute(DomainModelMsSqlServerContext context); 8 | void UnExecute(DomainModelMsSqlServerContext context); 9 | 10 | CommandDto ActualCommandDtoForNewState(string commandType); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/Commands/ICommandAdd.cs: -------------------------------------------------------------------------------- 1 | using AutoSaveCommandsApi.Models; 2 | 3 | namespace AutoSaveCommandsApi.Providers.Commands 4 | { 5 | public interface ICommandAdd : ICommand 6 | { 7 | void UpdateIdforNewItems(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/Commands/UpdateAboutDataCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using AutoSaveCommandsApi.Models; 4 | using Microsoft.Extensions.Logging; 5 | using Newtonsoft.Json.Linq; 6 | 7 | namespace AutoSaveCommandsApi.Providers.Commands 8 | { 9 | public class UpdateAboutDataCommand : ICommand 10 | { 11 | private readonly ILogger _logger; 12 | private readonly CommandDto _commandDto; 13 | private AboutData _previousAboutData; 14 | 15 | public UpdateAboutDataCommand(ILoggerFactory loggerFactory, CommandDto commandDto) 16 | { 17 | _logger = loggerFactory.CreateLogger("UpdateAboutDataCommand"); 18 | _commandDto = commandDto; 19 | } 20 | 21 | public void Execute(DomainModelMsSqlServerContext context) 22 | { 23 | _previousAboutData = new AboutData(); 24 | 25 | var aboutData = _commandDto.Payload.ToObject(); 26 | var entity = context.AboutData.First(t => t.Id == aboutData.Id); 27 | 28 | _previousAboutData.Description = entity.Description; 29 | _previousAboutData.Deleted = entity.Deleted; 30 | _previousAboutData.Id = entity.Id; 31 | 32 | entity.Description = aboutData.Description; 33 | entity.Deleted = aboutData.Deleted; 34 | _logger.LogDebug("Executed"); 35 | } 36 | 37 | public void UnExecute(DomainModelMsSqlServerContext context) 38 | { 39 | var aboutData = _commandDto.Payload.ToObject(); 40 | var entity = context.AboutData.First(t => t.Id == aboutData.Id); 41 | 42 | entity.Description = _previousAboutData.Description; 43 | entity.Deleted = _previousAboutData.Deleted; 44 | _logger.LogDebug("Unexecuted"); 45 | } 46 | 47 | public CommandDto ActualCommandDtoForNewState(string commandType) 48 | { 49 | if (commandType == CommandTypes.UNDO) 50 | { 51 | var commandDto = new CommandDto(); 52 | commandDto.ActualClientRoute = _commandDto.ActualClientRoute; 53 | commandDto.CommandType = _commandDto.CommandType; 54 | commandDto.PayloadType = _commandDto.PayloadType; 55 | 56 | commandDto.Payload = JObject.FromObject(_previousAboutData); 57 | return commandDto; 58 | } 59 | else 60 | { 61 | return _commandDto; 62 | } 63 | 64 | 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/Commands/UpdateHomeDataCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using AutoSaveCommandsApi.Models; 4 | using Microsoft.Extensions.Logging; 5 | using Newtonsoft.Json.Linq; 6 | 7 | namespace AutoSaveCommandsApi.Providers.Commands 8 | { 9 | public class UpdateHomeDataCommand : ICommand 10 | { 11 | private readonly ILogger _logger; 12 | private readonly CommandDto _commandDto; 13 | private HomeData _previousHomeData; 14 | 15 | public UpdateHomeDataCommand( ILoggerFactory loggerFactory, CommandDto commandDto) 16 | { 17 | _logger = loggerFactory.CreateLogger("UpdateHomeDataCommand"); 18 | _commandDto = commandDto; 19 | } 20 | 21 | public void Execute(DomainModelMsSqlServerContext context) 22 | { 23 | _previousHomeData = new HomeData(); 24 | 25 | var homeData = _commandDto.Payload.ToObject(); 26 | var entity = context.HomeData.First(t => t.Id == homeData.Id); 27 | 28 | _previousHomeData.Name = entity.Name; 29 | _previousHomeData.Deleted = entity.Deleted; 30 | _previousHomeData.Id = entity.Id; 31 | 32 | entity.Name = homeData.Name; 33 | entity.Deleted = homeData.Deleted; 34 | _logger.LogDebug("Executed"); 35 | } 36 | 37 | public void UnExecute(DomainModelMsSqlServerContext context) 38 | { 39 | var homeData = _commandDto.Payload.ToObject(); 40 | var entity = context.HomeData.First(t => t.Id == homeData.Id); 41 | entity.Name = _previousHomeData.Name; 42 | entity.Deleted = _previousHomeData.Deleted; 43 | _logger.LogDebug("Unexecuted"); 44 | } 45 | 46 | public CommandDto ActualCommandDtoForNewState(string commandType) 47 | { 48 | if (commandType == CommandTypes.UNDO) 49 | { 50 | var commandDto = new CommandDto(); 51 | commandDto.ActualClientRoute = _commandDto.ActualClientRoute; 52 | commandDto.CommandType = _commandDto.CommandType; 53 | commandDto.PayloadType = _commandDto.PayloadType; 54 | commandDto.Payload = JObject.FromObject(_previousHomeData); 55 | return commandDto; 56 | } 57 | else 58 | { 59 | return _commandDto; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/ICommandDataAccessProvider.cs: -------------------------------------------------------------------------------- 1 | using AutoSaveCommandsApi.Models; 2 | 3 | namespace AutoSaveCommandsApi.Providers 4 | { 5 | public interface ICommandDataAccessProvider 6 | { 7 | void AddCommand(CommandEntity command); 8 | 9 | void Save(); 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Providers/ICommandHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using AutoSaveCommandsApi.Models; 3 | 4 | namespace AutoSaveCommandsApi.Providers 5 | { 6 | public interface ICommandHandler 7 | { 8 | void Execute(CommandDto commandDto); 9 | CommandDto Undo(); 10 | CommandDto Redo(); 11 | 12 | List GetAll(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/Startup.cs: -------------------------------------------------------------------------------- 1 | using AutoSaveCommandsApi.ActionFilters; 2 | using AutoSaveCommandsApi.Providers; 3 | using Microsoft.AspNetCore.Builder; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.EntityFrameworkCore; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Microsoft.Extensions.Hosting; 9 | using Microsoft.OpenApi.Models; 10 | 11 | namespace AutoSaveCommandsApi 12 | { 13 | public class Startup 14 | { 15 | public Startup(IConfiguration configuration) 16 | { 17 | Configuration = configuration; 18 | } 19 | 20 | public IConfiguration Configuration { get; } 21 | 22 | public void ConfigureServices(IServiceCollection services) 23 | { 24 | var sqlConnectionString = Configuration.GetConnectionString("DataAccessMsSqlServerProvider"); 25 | 26 | services.AddDbContext(options => 27 | options.UseSqlServer(sqlConnectionString) 28 | ); 29 | 30 | services.AddScoped(); 31 | services.AddScoped(); 32 | services.AddScoped(); 33 | 34 | services.AddCors(options => 35 | { 36 | options.AddPolicy("AllowSpecificCorsUrls", 37 | builder => 38 | { 39 | builder 40 | .AllowCredentials() 41 | .WithOrigins( 42 | "https://localhost:4200") 43 | .SetIsOriginAllowedToAllowWildcardSubdomains() 44 | .AllowAnyHeader() 45 | .AllowAnyMethod(); 46 | }); 47 | }); 48 | 49 | services.AddControllers().AddNewtonsoftJson(); 50 | services.AddSwaggerGen(c => 51 | { 52 | c.SwaggerDoc("v1", new OpenApiInfo { Title = "AutoSaveCommandsApi", Version = "v1" }); 53 | }); 54 | } 55 | 56 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 57 | { 58 | if (env.IsDevelopment()) 59 | { 60 | app.UseDeveloperExceptionPage(); 61 | app.UseSwagger(); 62 | app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AutoSaveCommandsApi v1")); 63 | } 64 | 65 | app.UseCors("AllowSpecificCorsUrls"); 66 | 67 | app.UseHttpsRedirection(); 68 | 69 | app.UseRouting(); 70 | 71 | app.UseAuthorization(); 72 | 73 | app.UseEndpoints(endpoints => 74 | { 75 | endpoints.MapControllers(); 76 | }); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /AutoSaveCommandsApi/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*", 10 | "ConnectionStrings": { 11 | "DataAccessMsSqlServerProvider": "Data Source=.\\SQLEXPRESS;Initial Catalog=AngularAutoSaveCommands;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 damienbod 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular Auto-Save Commands 2 | 3 | [![.NET](https://github.com/damienbod/AngularAutoSaveCommands/workflows/.NET/badge.svg)](https://github.com/damienbod/AngularAutoSaveCommands/actions?query=workflow%3A.NET) 4 | 5 | Articles in this series: 6 | 7 |
    8 |
  1. Implementing UNDO, REDO in ASP.NET Core
  2. 9 |
  3. Angular Auto Save, Undo and Redo
  4. 10 |
  5. ASP.NET Core Action Arguments Validation using an ActionFilter
  6. 11 |
12 | 13 | ## History 14 | 15 | 2021-01-19: Updated to ASP.NET Core 5, Angular CLI 11.0.9 16 | 17 | 2019-09-23: Updated to ASP.NET Core 3.0, Angular 8.2.7 18 | 19 | 2019-09-01: Updated npm packages 20 | 21 | 2019-08-19: Updated to ASP.NET Core 3.0 Preview 8, updating npm packages 22 | 23 | 2019-07-31: Updated to ASP.NET Core 3.0 Preview 7 24 | 25 | 2019-07-31: Updated to Angular 8.1.3 26 | 27 | 2019-05-03: Updated to Angular 7.2.14, nuget packages, in-process 28 | 29 | 2019-03-15: Updated to Angular 7.2.9, nuget packages 30 | 31 | 2019-02-16: Updated to Angular 7.2.4, ASP.NET Core 2.2 nuget packages 32 | 33 | 2018-11-22: Updated to Angular 7.1.0, nuget packages 34 | 35 | 2018-09-28: Updated to Angular 6.1.9, ,NET 2.1.4 36 | 37 | 2018-06-16: Updated to Angular 6.0.5 38 | 39 | 2018-06-16: Updated to ASP.NET Core 2.1 40 | 41 | 2018-02-11: Updated to ASP.NET Core All 2.0.5 and Angular 5.2.4 42 | 43 | 2017-08-19: Updated to ASP.NET Core 2.0 and Angular 4.3.5 44 | 45 | 2017-02-03: Updated to Angular 2.4.5 and webpack 2.2.1, VS2017 RC3, msbuild3 46 | 47 | 2017-01-04: Updated to Angular 2.4.1 and webpack 2.2.0-rc.3 48 | 49 | 2016-12-23: Updated to Visual Studio 2017 and ASP.NET Core 1.1 --------------------------------------------------------------------------------