Giter Site home page Giter Site logo

Comments (2)

tidyui avatar tidyui commented on June 29, 2024

There seems to be a typo in the official documentation. This would be the correct way to add the options in your Program.cs

builder.AddPiranha(options =>
{

   ...

   options.UseManager(o => {
        o.JsonOptions = (jsonOptions) =>
        {
            jsonOptions.SerializerSettings.ContractResolver = new DefaultContractResolver();
        };
    });

   ...

});

Regards

from piranha.core.

VikneshSubramaniyan avatar VikneshSubramaniyan commented on June 29, 2024

using System;
using Dapper;
//using Hangfire;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Serialization;
using Piranha;
using Piranha.AttributeBuilder;
using Piranha.ImageSharp;
using Piranha.Local;
//using Piranha.Manager.Binders;
using SendbackPortal.Data;
using SendbackPortal.Jobs;
using SendbackPortal.Models;
using SendbackPortal.Models.AccountViewModels;
using SendbackPortal.Models.Templates;
using SendbackPortal.Repositories;
using SendbackPortal.Services;
using EntityFrameworkCore.UseRowNumberForPaging;
using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
using Newtonsoft.Json;
using Piranha.Manager.TinyMCE;
using Piranha.Data.EF.SQLServer;
using Piranha.Manager.LocalAuth;
using Piranha.Manager.Editor;

namespace SendbackPortal
{

/// <summary>
/// Application configuration
/// </summary>
public class Startup
{
    public Startup(IConfiguration configuration, IHostingEnvironment env)
    {
        Configuration = configuration;
        var contentRoot = configuration.GetValue<string>(WebHostDefaults.ContentRootKey);
    }

    public IConfiguration Configuration { get; }
    public string conn; 
    // This method gets called by the runtime. Use this method to add services to the container.
    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        // Get connection strings from the appsettings.json file
        var defaultConnection = Configuration.GetConnectionString("DefaultConnection");
        var advConnection = Configuration.GetConnectionString("ADVConnection");
        conn = advConnection;
       
        // BB 5/16/2018 - make compatible with SQL Server 2008R2
        services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(defaultConnection, b => b.UseRowNumberForPaging()));
        services.AddDbContext<SQLServerDb>(options => options.UseSqlServer(defaultConnection, b => b.UseRowNumberForPaging()));
        services.AddDbContext<DefaultDBContext>(options => options.UseSqlServer(defaultConnection, b => b.UseRowNumberForPaging()));
        services.AddDbContext<AdvDbContext>(options => options.UseSqlServer(advConnection, b => b.UseRowNumberForPaging()));
        //services.AddDbContext<AdvPhysicianMessengerDbContext>(options => options.UseSqlServer(advPhysicianMessengerConnection, b => b.UseRowNumberForPaging()));
        
        // Set up the authentication for the application
        services.AddIdentity<ApplicationUser, IdentityRole>(options => {
            options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+/' ";
        })
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders()
            .AddErrorDescriber<CustomIdentityErrorDescriber>(); // Add this line

        
        services.Configure<DataProtectionTokenProviderOptions>(o => o.TokenLifespan = TimeSpan.FromDays(14));
        //services.Configure<DataProtectionTokenProviderOptions>(o => o.TokenLifespan = TimeSpan.FromMinutes(2));   // minutes for testing purposes

        // Add Global singletons
        services.AddSingleton(Configuration);
        services.AddSingleton<IStorage, FileStorage>();
        services.AddSingleton<IImageProcessor, ImageSharpProcessor>();
        services.AddTransient<ISecurity, IdentitySecurity>();
        services.AddScoped<IDb, SQLServerDb>();
        services.AddScoped<IApi, Api>();

        // Allow the this application to use the Piranha manager
        services.AddPiranha(options =>
        {
            options.UseCms();
            options.UseManager(o => {
                o.JsonOptions = (jsonOptions) =>
                {
                    jsonOptions.SerializerSettings.ContractResolver = new DefaultContractResolver();
                };
            });
            options.UseFileStorage(naming: Piranha.Local.FileStorageNaming.UniqueFolderNames);
            options.UseImageSharp();
           
            options.UseTinyMCE();
            
            //options.UseMemoryCache();
            options.UseEF<SQLServerDb>(db =>
                db.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            //options.UseIdentityWithSeed<IdentitySQLServerDb>(db =>
            //    db.UseSqlServer("DefaultConnection"));
        });


       
        services.AddTransient<IEmailSender, EmailSender>();
        services.AddTransient<IUserRepository, UserRepository>();
        services.AddTransient<ISendbackRepository, SendbackRepository>();
        services.AddTransient<IUsersMappingRepository, UsersMappingRepository>();
        services.AddTransient<IPhysicianMessengerRepository, PhysicianMessengerRepository>();
        services.AddTransient<ILocationExclusionRepository, LocationExclusionRepository>();

        services.AddSession();

        return services.BuildServiceProvider();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider services)
    {

        // Show useful error messages if the application is in development
        if (env.IsDevelopment())
        {
            app.UseBrowserLink();
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        DefaultTypeMap.MatchNamesWithUnderscores = true;
       
        // Initialize Piranha
        var api = services.GetService<IApi>();
        App.Init(api);

        var pageTypeBuilder = new ContentTypeBuilder(api)
            .AddType(typeof(BlogArchive))
            .AddType(typeof(StandardPage));
        pageTypeBuilder.Build(); 
        var postTypeBuilder = new ContentTypeBuilder(api)
            .AddType(typeof(BlogPost));
       postTypeBuilder.Build(); 
        EditorConfig.FromFile("editorconfig.json");

        // Register middleware
        app.UseStaticFiles();
        //app.UseRouting();
        app.UseAuthentication();
      // app.UseAuthorization();
        app.UseMiddleware<PasswordMiddleware>();

        
        app.UsePiranha(options =>
        {
            options.UseManager();
            options.UseTinyMCE();
        });
        
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
           name: "default",
           pattern: "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapPiranhaManager();
        });
    }
}

}

still piranha manger function is breaking ..JSON serialization did not work

from piranha.core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.