📜 ⬆️ ⬇️

Universal data management system based on scaffolding technology and the .NET Core platform

A few years ago, I implemented a number of projects that were managed using an ASP.NET Dynamic Data based management system. At one time, this system saved a lot of time and resources. But as you know, in IT everything is developing very rapidly. Not so long ago, the .NET Core platform was released, the main innovation of which was cross-platform support. This, in turn, allowed me to migrate a number of small projects, as well as projects that I support on a non-profit basis on budget servers from Digital Ocean, which, as is known, support only Linux operating systems. When it came to the control system, I had a choice - with minimal changes in the code, to port the project to Mono, or to rewrite from scratch using the new .NET Core features. After weighing all the pros and cons, I chose the second option. What came of it and what I am going to get you can find out under the cut.



For those who do not know what scaffolding is, a brief description of this approach:
" Scaffolding is a metaprogramming method for creating web applications that interact with the database. This method is supported by some modern MVC frameworks (Grails, Yii, Ruby on Rails, Django, CakePHP, Phalcon PHP, Symfony, ASP.NET Dynamic Data and other .) The developer in them sets the specifications for which the program code is subsequently generated for creating, reading, updating and deleting certain records in the database. "[1]

Inspired by the example of Ruby on Rail in 2007, Microsoft developed its tool for quickly designing web applications that work with data.

" ASP.NET Dynamic Data is a framework that allows you to quickly develop full-featured data-driven applications using LINQ to SQL or the Entity Framework, and also extends the capabilities of the DetailsView, FormView, GridView and ListView controls in terms of functionality, data validation and display.
To put it simply, Dynamic Data is designed to quickly generate front-end for Microsoft SQL Server databases. "[2]

I liked the approach and the ASP.NET Dynamic Data tool. And so much so that as I wrote above, I created my own system based on them. However, while using this solution, I had various ideas about how this product could be improved. And so, in order to rewrite the project from scratch, I was pushed by a number of flaws in the ASP.NET Dynamic Data based solution, including the main ones:
')

Based on these shortcomings, I identified for myself a number of opportunities that I would like to realize in a new project:


The general principle of the system


At the moment, the main part of the code is already written, which allows you to work with the data of uncomplicated databases.

The work procedure is as follows:

  1. A working directory is created for the database, which is specified in the base application configuration file.

  2. In this directory, a file is created with information about the database connection parameters and file storage connection parameters, as well as the system user accounts are configured.

  3. Then, after the first launch of the system, the user goes to the Administration section and starts the process of building a database model, which will be saved to the working directory in the db.json file.

  4. After the model is built, in principle, you can already work with the system. However, for completely comfortable work, you may need to clarify the parameters of some fields. To simplify the procedure of supporting the configuration file in the future, I provided the opportunity to describe the updated configuration in a separate db_ex.json file. This file is similar in structure to db.json , but it only needs to specify the name of the field, which requires additional configuration and specify those parameters that differ from those generated by default. Splitting the configuration into two separate files allows you not to worry that if in the future you have to update the data model, all custom settings will be lost. And this can happen, for example, if new fields were added to the table, or a new table was created in the database.




Configuration





Base Description Structure
Scheme

  • Name - the system name of the scheme.
  • Title - the title. Displayed in the system interface
  • Tables - a list of tables


Table

  • ShowInList - the parameter specifies whether the table will be displayed in the navigation menu
  • Name - the system name of the table. Corresponds to the name of the table in the database.
  • Title - the title of the table. It is displayed in the navigation menu and on the page for editing the table.
  • Description - the description. Appears on the table edit page
  • Columns - list of fields


Field

  • Position - the position of the field in the grid and editor.
  • IsKey - is the field a key field in the database
  • IsNullable - whether NULL values ​​are valid in the field
  • Reference - ...
  • ShowInGrid - display, or not a field in the grid
  • AutoIncrement - whether the field is auto-increment
  • MaxValue - maximum field value
  • MinValue - maximum field value
  • MaxLength - maximum field length
  • Readonly - whether the field is read-only.
  • Type - field type
  • Name - system field name, corresponds to the field name in the database table
  • Title - the name of the field, displayed in the editor and grid
  • Description - field description


Data Type Support

At the moment, the following editors for various field types are provided (but not all have been implemented yet):
  • Text - plain text field
  • Email - field for entering postal address
  • Url - url input field
  • Phone - phone entry field
  • HTML - field containing full WYSIWYG editor.
  • Password - password field
  • Date - date field
  • Time - time entry field
  • DateTime - field for entering time and date
  • File - field to load the file and save the identifier of the loaded file to the table
  • Integer - field for input of integers
  • Double - field for entering fractional numbers
  • Image - a field for loading an image, previewing the loaded image and saving the identifier of the loaded image to a table
  • Binary - a field for loading a file and saving the contents into a table,
  • Reference - a drop-down list, or a pop-up window with the ability to search to select the associated value.
  • Boolean - checkbox



Sample db.json configuration file
{ "Tables": [ { "Columns": [ { "Position": 1, "IsKey": true, "IsNullable": false, "Reference": null, "ShowInGrid": false, "AutoIncrement": true, "MaxValue": null, "MinValue": null, "MaxLength": null, "Readonly": true, "Type": 40, "Name": "Id", "Title": "Id", "Description": "" }, { "Position": 2, "IsKey": true, "IsNullable": false, "Reference": null, "ShowInGrid": false, "AutoIncrement": true, "MaxValue": null, "MinValue": null, "MaxLength": null, "Readonly": true, "Type": 40, "Name": "Name", "Title": "Name", "Description": "" }, { "Position": 3, "IsKey": true, "IsNullable": false, "Reference": null, "ShowInGrid": false, "AutoIncrement": true, "MaxValue": null, "MinValue": null, "MaxLength": null, "Readonly": true, "Type": 40, "Name": "Value", "Title": "Value", "Description": "" } ], "ShowInList": false, "Name": "Setting", "Title": "", "Description": " " } ], "Generated": "2016-09-27T00:40:48.9189786+03:00", "ExtendedConfigurationLoaded": false, "Name": "Database", "Title": "Database" } 



Sample db_ex.json configuration file
 { "Tables": [ { "Columns": [ { "Type": 40, "ShowInGrid": false, "AutoIncrement": true, "Readonly": true, "Name": "Id", "Title": " " }, { "Type": 10, "Name": "Name", "Title": "" }, { "Type": 10, "Name": "Value", "Title": "" } ], "ShowInList": false, "Name": "Setting", "Title": "", "Description": " " } ], "Name": " ", "Title": " " } 



Sample configuration.json configuration file
 { "ConnectionString": "Server=...;Database=...;User Id=...;Password=..;", "SecretKey": "secret-key-123", "ApplicationRestartCommand": "", "StorageConfiguration": { "Type": 0, "Url": "http://static.exapmle.com/user_upload/", "Connection": { "Path": "/var/www/example.com/user_upload/" } }, "Users": [{ "Login": "admin", "Password": "admin", "Administrator": true } ] } 



File storage



The plans also include the implementation of integration with the Amazon S3 repository.

Afterword


I want to thank gelas for help in working on the project and sensible criticism.

Separately, I want to note that the project was created by me in the community of Ukrainian developers. NET Core -. NET Core Ukrainian User Group . At the moment, the greatest activity of the participants is observed in the group on Facebook, but we also plan to fill the group in the VC. If you have questions on .NET Core, ideas that you want to share, or you are just eyeing this technology - join, it will be interesting!

The project is available under the MIT license on GitHub .



1. ASP.NET Dynamic Data Guide.
2. Wikipedia. Scaffolding

Source: https://habr.com/ru/post/311822/


All Articles