This is a very basic ASP.NET Core 2.2 Web Application (MVC) project (using .Net Core 2.2, Microsoft.EntityFrameworkCore, log4net).
The goal is to build a MVC web project by implementing a service to upload transaction data from CSV/XML file formats into database and query transactions by specified criteria.
The App has these functionalities:
- It maintains a Controller named FileUploadController, which process CSV/XML file and store transaction data into database.
- It has an another Controller named TransactionController, which can get transactions from database according to following criteria:
- Using currency code
- Using date range
- Using status
To run the App, you have to do following things first:
- Execute the sql script:
- Change the DbConnection string from appsettings.json as per your DB server configuration.
The FileUploadController receives either CSV/XML file from the user and sends it to a FileHandlerFactory class. This factory returns the actual FileHandler instance based on the file extension. FileHandler instance then parse the file content and load the db Transactions models from it. It also identifies the invalid items from file contents.
FileMetadataValidationFilter is implemented to validate the unsupported file extension and file size. If the file does not match the validation criteria, it will give an error message and request will not move forward to the FileUploadController.
It can identify the missing mandatory items and treat the file as invalid.
On a successful file upload it will show a success message.
TransactionController has 3 actions to get all the transactions based on the above mentioned criteria .
There is a TransactionService, which handles the core business logic to get the transactions from the database using those criteria and send the result to the Controller. Transaction response for any criteria will return a json array.
Below is an example of performing UI validation.
Dbcontext is generated by using bellow scaffold command:
Scaffold-DbContext 'data source=REL-LAP-18;initial catalog=TransactionDb;user id=sa;password=Welcome@2019' Microsoft.EntityFrameworkCore.SqlServer -Context TransactionDbContext -OutputDir DbModels -Force -Tables "Transactions", "TransactionStatus"
Note: If multiple Transactions have the same TransactionId, in my project I am considering them as a new unique Transaction and designed the database model accordingly.
log4net library is used for maintaining all kind of logging with the support of log levels: Debug, Info, Warn, Error, Fatal. A log4net.config file is used to maintain it's configuration. As per the current configuration logs will be written in the filepath: Logs\app.log.
Logs are written in the important places of the controllers and other classes. Besides a LoggingFilter is introduced to track the execution time of a controller.
A sample app.log will look like:
GlobalExceptionFilter is implemented to handle the application exception in a common place and log it from there. Also it will re-direct the request to a page where general global exception will be displayed in a short format.
Visual Studio 2017, SQL Server 2014, ASP.NET Core 2.2, log4net.