using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Components.Notifications;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.BlazoriseUI;
[Dependency(ReplaceServices = true)]
public class BlazoriseUiNotificationService : IUiNotificationService, IScopedDependency
{
///
/// An event raised after the notification is received.
///
public event EventHandler? NotificationReceived;
public Task Info(string message, string? title = null, Action? options = null)
{
var uiNotificationOptions = CreateDefaultOptions();
options?.Invoke(uiNotificationOptions);
NotificationReceived?.Invoke(this, new UiNotificationEventArgs(UiNotificationType.Info, message, title, uiNotificationOptions));
return Task.CompletedTask;
}
public Task Success(string message, string? title = null, Action? options = null)
{
var uiNotificationOptions = CreateDefaultOptions();
options?.Invoke(uiNotificationOptions);
NotificationReceived?.Invoke(this, new UiNotificationEventArgs(UiNotificationType.Success, message, title, uiNotificationOptions));
return Task.CompletedTask;
}
public Task Warn(string message, string? title = null, Action? options = null)
{
var uiNotificationOptions = CreateDefaultOptions();
options?.Invoke(uiNotificationOptions);
NotificationReceived?.Invoke(this, new UiNotificationEventArgs(UiNotificationType.Warning, message, title, uiNotificationOptions));
return Task.CompletedTask;
}
public Task Error(string message, string? title = null, Action? options = null)
{
var uiNotificationOptions = CreateDefaultOptions();
options?.Invoke(uiNotificationOptions);
NotificationReceived?.Invoke(this, new UiNotificationEventArgs(UiNotificationType.Error, message, title, uiNotificationOptions));
return Task.CompletedTask;
}
protected virtual UiNotificationOptions CreateDefaultOptions()
{
return new UiNotificationOptions();
}
}