Ejemplo n.º 1
0
 public ToastMessage(string message, string title, Enums.ToastType toasType, ToastOption options = null)
 {
     this.Message      = message;
     this.Title        = title;
     this.ToastType    = toasType;
     this.ToastOptions = options;
 }
Ejemplo n.º 2
0
        public void AddErrorToastMessage(string message = null, string title = null, ToastOption toastOptions = null)
        {
            var toastMessage = new ToastMessage(message ?? _defaultNtoastNotifyOptions.ErrorMessage, title ?? _defaultNtoastNotifyOptions.ErrorTitle, ToastEnums.ToastType.Error, toastOptions);

            AddMessage(toastMessage);
        }
Ejemplo n.º 3
0
        public void AddToastMessage(string title, string message, ToastEnums.ToastType notificationType, ToastOption toastOptions)
        {
            var toastMessage = new ToastMessage(message, title, notificationType, toastOptions);

            AddMessage(toastMessage);
        }
Ejemplo n.º 4
0
        public static IServiceCollection AddNToastNotify(this IServiceCollection services, ToastOption defaultOptions = null, NToastNotifyOption nToastNotifyOptions = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var assembly = typeof(Components.ToastrViewComponent).GetTypeInfo().Assembly;
            //Create an EmbeddedFileProvider for that assembly
            var embeddedFileProvider = new EmbeddedFileProvider(assembly, "NToastNotify");

            //Add the file provider to the Razor view engine
            services.Configure <RazorViewEngineOptions>(options =>
            {
                options.FileProviders.Add(embeddedFileProvider);
            });

            //Add the ToastNotification implementation
            services.AddScoped <IToastNotification, ToastNotification>();

            //Check if a TempDataProvider is already registered.
            var provider         = services.BuildServiceProvider();
            var tempDataProvider = provider.GetService <ITempDataProvider>();

            if (tempDataProvider == null)
            {
                //Add a tempdata provider when one is not already registered
                services.AddSingleton <ITempDataProvider, CookieTempDataProvider>();
            }

            //Add TempDataWrapper for accessing and adding values to tempdata.
            services.AddScoped <ITempDataWrapper, TempDataWrapper>();

            //check if HttpContextAccessor is not registered.
            var httpContextAccessor = provider.GetService <IHttpContextAccessor>();

            if (httpContextAccessor == null)
            {
                services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            }

            // Add the toastr default options that will be rendered by the viewcomponent
            defaultOptions = defaultOptions ?? ToastOption.Defaults;
            services.AddSingleton(defaultOptions);

            // Add the NToastifyOptions to the services container for DI retrieval (options that are not rendered as they are not part of the toastr.js plugin)
            nToastNotifyOptions = nToastNotifyOptions ?? NToastNotifyOption.Defaults;
            services.AddSingleton((NToastNotifyOption)nToastNotifyOptions);
            return(services);
        }
Ejemplo n.º 5
0
        public void AddWarningToastMessage(string message = null, string title = null, ToastOption toastOptions = null)
        {
            var toastMessage = new ToastMessage(message ?? _defaultNtoastNotifyOptions.WarningMessage, title ?? _defaultNtoastNotifyOptions.WarningTitle, Enums.ToastType.Warning, toastOptions);

            AddMessage(toastMessage);
        }
Ejemplo n.º 6
0
        public void AddInfoToastMessage(string message, string title = null, ToastOption toastOptions = null)
        {
            var toastMessage = new ToastMessage(message ?? _defaultNtoastNotifyOptions.InfoMessage, title ?? _defaultNtoastNotifyOptions.InfoTitle, Enums.ToastType.Info, toastOptions);

            AddMessage(toastMessage);
        }
Ejemplo n.º 7
0
        public void AddSuccessToastMessage(string message = null, string title = null, ToastOption toastOptions = null)
        {
            var toastMessage = new ToastMessage(message ?? _defaultNtoastNotifyOptions.SuccessMessage, title ?? _defaultNtoastNotifyOptions.SuccessTitle, Enums.ToastType.Success, toastOptions);

            AddMessage(toastMessage);
        }
        private static IMvcBuilder AddNToastNotifyToMvcBuilder(this IMvcBuilder mvcBuilder, ToastOption defaultOptions = null,
                                                               NToastNotifyOption nToastNotifyOptions = null)
        {
            var services = mvcBuilder.Services;

            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            //Add the file provider to the Razor view engine
            services.Configure <RazorViewEngineOptions>(options =>
            {
                options.FileProviders.Add(GetEmbeddedFileProvider());
            });

            //This is a fix for Feature folders based project structure. Add the view location to ViewLocationExpanders.
            mvcBuilder?.AddRazorOptions(o =>
            {
                o.ViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });

            //Add the ToastNotification implementation
            services.AddScoped <IToastNotification, ToastNotification>();

            //Check if a TempDataProvider is already registered.
            var provider         = services.BuildServiceProvider();
            var tempDataProvider = provider.GetService <ITempDataProvider>();

            if (tempDataProvider == null)
            {
                //Add a tempdata provider when one is not already registered
                services.AddSingleton <ITempDataProvider, CookieTempDataProvider>();
            }

            //Add TempDataWrapper for accessing and adding values to tempdata.
            services.AddScoped <ITempDataWrapper, TempDataWrapper>();

            //check if HttpContextAccessor is not registered.
            var httpContextAccessor = provider.GetService <IHttpContextAccessor>();

            if (httpContextAccessor == null)
            {
                services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            }

            // Add the toastr default options that will be rendered by the viewcomponent
            defaultOptions = defaultOptions ?? ToastOption.Defaults;
            services.AddSingleton(defaultOptions);

            // Add the NToastifyOptions to the services container for DI retrieval (options that are not rendered as they are not part of the toastr.js plugin)
            nToastNotifyOptions = nToastNotifyOptions ?? NToastNotifyOption.Defaults;
            services.AddSingleton((NToastNotifyOption)nToastNotifyOptions);
            services.AddSingleton <IMessageContainerFactory, MessageContainerFactory>();
            services.AddScoped <NtoastNotifyMiddleware>();
            return(mvcBuilder);
        }
 public static IMvcBuilder AddNToastNotify(this IMvcBuilder mvcBuilder, ToastOption defaultOptions = null,
                                           NToastNotifyOption nToastNotifyOptions = null)
 {
     return(AddNToastNotifyToMvcBuilder(mvcBuilder, defaultOptions, nToastNotifyOptions));
 }
 public static IServiceCollection AddNToastNotify(this IServiceCollection services, ToastOption defaultOptions = null, NToastNotifyOption nToastNotifyOptions = null, IMvcBuilder mvcBuilder = null)
 {
     return(services);
 }