Project setup

DataWeb integrates seamlessly into an ASP.NET Core project, and it is therefore possible to create an empty web app, add NuGet packages, and manually configure the code.

However, there is a much faster way to achieve the same result: simply install and use the dedicated dotnet template. This template is updated with every new release and allows you to have an ASP.NET Core site with DataWeb active in just a few minutes.
 
Installation of the DataWebApp dotnet template

The DataWebApp template contains a basic ASP.NET Core project with everything you need to start developing with DataWeb immediately. From the command line, install the latest version from the corresponding NuGet package:
 
dotnet new install "\\MyNuGetPath\DataWeb.TemplateApp.10.7.50.nupkg"
 
If you receive an error because a previous version of the template is already present, you can remove it with this command:
 
dotnet new uninstall DataWeb.TemplateApp
 
With this command, you can check that DataWebApp is part of the installed templates:
 
dotnet new list
 
Creating the project and solution

This section explains how to create a new ASP.NET Core project with DataWeb from the command line and associate it with a solution.
Navigate to the folder where you want to create the project and execute:
 
dotnet new datawebapp -o MyApp
 
where MyApp is the name of the project. Note that this name will also be used for the code's namespace.
Now proceed with creating the solution that will contain your project:
 
dotnet new sln -n MyApp
 
and finally, associate the project with the solution:
 
dotnet sln MyApp.sln add MyApp\MyApp.csproj
 
The ASP.NET Core project with DataWeb is ready!
Open it in Visual Studio Code (or Visual Studio if you prefer). You will find a structure like this:
 
Project structure

Start the project with F5, and after a brief compilation, you will find the welcome page at https://localhost:5001. Hurray!
 
DataWeb startup
 
Project settings
 
The template sets up the appsettings.json configuration file with a series of standard settings.
Now is the time to customize the values and configure the connection string to the database (this section does not go into the details of creating a database on SQL Server).

Creating the data structure
 
The last step concerns the creation of the data structure in the SQL Server database dedicated to the project.
The app already includes the DataWeb.DevOps.SqlServer package, which is dedicated to database installation and update activities.
In particular, the DevOpsController contains the necessary code to perform the database setup:
 
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using DataWeb.DevOps.SqlServer;

namespace MyApp.Controllers
{
    public class DevOpsController : Controller
    {
        private readonly InstallService installService;

        public DevOpsController(InstallService installService)
        {
            this.installService = installService;
        }

        public async Task<IActionResult> Install()
        {
            await installService.InstallAsync();

            return Content("Install completed");
        }
    }
}
 
All that's left to do is to execute the associated endpoint https://localhost:5001/devops/install and wait for the task to complete.

Once "Install completed" appears, the data structure creation is complete, and we can start using DataWeb at https://localhost:5001/dataweb. Well done!