JCTools.GenericCrud 2.0.0-beta2

This is a prerelease version of JCTools.GenericCrud.
There is a newer version of this package available.
See the version list below for details.
dotnet add package JCTools.GenericCrud --version 2.0.0-beta2                
NuGet\Install-Package JCTools.GenericCrud -Version 2.0.0-beta2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JCTools.GenericCrud" Version="2.0.0-beta2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JCTools.GenericCrud --version 2.0.0-beta2                
#r "nuget: JCTools.GenericCrud, 2.0.0-beta2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JCTools.GenericCrud as a Cake Addin
#addin nuget:?package=JCTools.GenericCrud&version=2.0.0-beta2&prerelease

// Install JCTools.GenericCrud as a Cake Tool
#tool nuget:?package=JCTools.GenericCrud&version=2.0.0-beta2&prerelease                

JCTools.GenericCrud

Simplification of the Create, Read, Update and Delete web pages of the application models.

Overview

All application required multiple pages for edited the base models. This pages generally are equals to each other.

This package allows reduce this task at minimum of actions.

You only require create and configure your models, and this package create the necessary controllers, views and actions for the Create, Read, Update and Delete actions.

Status

v2.0.0-beta2

Requirements

.net core 2.1

bootstrap 3.3.7 or bootstrap 4.3.1

font awesome 5.0.6

Usage

  1. Add the package to your application
Install-Package JCTools.GenericCrud -Version 2.0.0-beta2

Or

dotnet add package JCTools.GenericCrud --version 2.0.0-beta2
  1. Add the next lines in the method ConfigureServices of your Startup class
    services.ConfigureGenericCrud<MyContext>(options =>
    {
        // options is an instance from JCTools.GenericCrud.Settings.IOptions
        // use this interface to custom the generated CRUDs globally
        // eg;

        // Indicate if desired use Modals
        options.UseModals = true;
        // Set the bootstrap version to be used (default v4.3.1)
        options.BootstrapVersion = Settings.Bootstrap.Version3;
        // add the models type to manage with the package
        options.Models.Add<Models.Country>(); 
        options.Models.Add<Models.Genre>(nameof(Models.Genre.Name));
        
        // add a model with a custom controller
        options.Models.Add<Models.Movie, int, MovieController, Data.Context>();
    });

Note: From the version 2.0.0 the next features was marked how to obsolete and will be removed in future versions: - The method o.Models.Add(Type modelType, string keyPropertyName = "Id", string controllerName = ""). - The ContextCreator option

  1. Run to app and access at the url http://localhost:5000/[ModelName], sample: http://localhost:5000/Country. In the browser you should see a similar page to : Sample index page

Custom controllers

If your desired personalize your controllers, add additional actions or override the default actions, then

  1. Create a new controller the inherits from JCTools.GenericCrud.Controllers.GenericController. e.g;
using System;
using System.Linq;
using JCTools.GenericCrud.Controllers;
using JCTools.GenericCrud.Services;
using JCTools.GenericCrud.DataAnnotations;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;

namespace MyApp.Controllers
{
    [CrudConstraint(typeof(Models.MyModel))]
    public class MyController : GenericController
    {
        public MyController(
            IServiceProvider serviceProvider,
            IViewRenderService renderingService,
            IStringLocalizerFactory localizerFactory,
            ILoggerFactory loggerFactory
        )
            : base(serviceProvider, renderingService, localizerFactory, loggerFactory, "Id")
        {
            // add your custom logic here
        }
    }
}

Note: In the version 2.0.0 the Settings property of the controller has initialized in the OnActionExecuting(ActionExecutingContext filterContext) or OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) controller methods; You should move their custom settings of the controller constructor to this methods.

  1. Add the related model in the method ConfigureServices of your Startup class using specifying the custom controller, eg;
    options.Models.Add<Models.Movie, int, MovieController, Data.Context>();
  1. (optional) If you override the OnActionExecuting(ActionExecutingContext filterContext) or OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) controller methods, make sure to invoke the base methods for the correct initializations of the controller settings
    //...
    
    public override void OnActionExecuting(ActionExecutingContext context)
    {
        // Call the initialization of the Settings property
        base.InitSettings(context);
        // Add your custom settings here, eg;
        Settings.UseModals = false;
        Settings.Subtitle = "All entities";
        ViewBag.OtherEntities = (DbContext as Data.Context).OtherEntities.ToList();

        base.OnActionExecuting(context);
    }
    
    public override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
    {
        // Call the initialization of the Settings property
        base.InitSettings(context);
        // Add your custom settings here, eg;
        Settings.UseModals = false;
        Settings.Subtitle = "All entities";
        ViewBag.OtherEntities = (DbContext as Data.Context).OtherEntities.ToList();

        return base.OnActionExecutionAsync(context, next);
    }
    //...
  1. Run to app and access at the url http://localhost:5000/Movie,

Changes of the version 2.0.0

  • Add support to Bootstrap 4.0
  • Replaces the GenericController<TContext, TModel, TKey> class for the GenericController class
    • This new class is easier to use
  • The follows interfaces was replaced for a best definition and structure:
    • IBase → IViewModel
    • IBaseDetails, ICrudDetails → IDetailsModel
    • ICrudEdit → IEditModel
    • ICrudList → IIndexModel
  • The follows models was replaced by the CrudModel class
    • Base
    • CrudDetails
    • CrudEdit
    • CrudList
  • The IControllerOptions interface and ControllerOptions class was removed for being unnecessary in the new structure
  • The extensors methods GetLocalizedString(...) for the IStringLocalizer interfaces was moved to the StringLocalizerExtensors class
  • Now no need to use endpoint mapping, if you use older version remove the next code from the method Configure your startup class:
    app.UseMvc(routes =>
    {
        routes.MapCrudRoutes(); // remove this line

        // ...
    });   

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.2 347 12/8/2022
2.2.1 406 3/14/2021
2.2.0 352 2/2/2021
2.1.0 375 1/19/2021
2.1.0-beta1 306 1/10/2021
2.0.0 389 1/9/2021
2.0.0-beta4 293 1/6/2021
2.0.0-beta2 229 1/4/2021
2.0.0-beta1 295 12/27/2020
1.0.5 1,018 5/11/2018
1.0.4.2 1,066 5/8/2018
1.0.4.1 1,055 5/8/2018
1.0.4 1,014 5/7/2018
1.0.3 1,033 5/6/2018
1.0.2 1,037 4/19/2018
1.0.1 1,059 4/13/2018
1.0.0 1,071 3/19/2018