Skip to content

engr-monirujjaman/notification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notification

This package is an asp net core mvc toaster notificaton helping tool.

Dependency

.NET 6 & .NET 7

Why you are use this package?

  • Provide dependency Injection
  • Ajax request support
  • Customizable settings

Install

Install-Package Monirujjaman.AspNetCore.Mvc.Toaster.Notification

Installation In MVC Project

Step-1

Add dependency Injection in the program.cs file Example: builder.Services.AddNotification();

Step-2

Add middleware in the program.cs file Example: app.UseNotification();

Step-3

Add the component end of the layout body which layout pages you want to use Example: @await Component.InvokeAsync("Notification")

Example

Setp-1 & Step-2

using Notification.Extensions;  
  
var builder = WebApplication.CreateBuilder(args);  
  
builder.Services.AddControllersWithViews(); 
  
builder.Services.AddNotification();  
  
var app = builder.Build();  

app.UseNotification();

app.MapControllerRoute(  
 name: "default",  
 pattern: "{controller=Home}/{action=Index}/{id?}");  
  
app.Run();

Setp-3

<!DOCTYPE html>  
<html lang="en">  
<head>  
 <title>Title</title>  
 <link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>  
  @await RenderSectionAsync("Links", required: false)  
</head>  
<body>  
  
@RenderBody()  
  
<script src="~/js/site.js" asp-append-version="true"></script>  
  
@await RenderSectionAsync("Scripts", required: false)  
  
@await Component.InvokeAsync("Notification")  
  
</body>  
</html>

Usage

using Microsoft.AspNetCore.Mvc;  
using Notification.Services.Contracts;  
  
namespace HostelApp.Web.Controllers;  
  
public class HomeController : Controller  
{  
	  private readonly INotificationService _notificationService;  
  
	  public HomeController(INotificationService notificationService)  
	  {  _notificationService = notificationService;  
	  }  
	  
	  public IActionResult Index()  
	  {  
		  _notificationService.Success("My success message", "Success Title!");  
		  _notificationService.Error("My Error message", "Error Title!");  
		  _notificationService.Information("My Information message", "Information Title!");  
		  _notificationService.Warning("My Warning message", "Warning Title!");  
		  return View();  
	  }
}

Output

image

Customization Settings

using Notification.Extensions;  
  
var builder = WebApplication.CreateBuilder(args);  
  
builder.Services.AddControllersWithViews(); 
  
builder.Services.AddNotification(config =>  
{  
 config.Debug = false;  
 config.CloseButton = false;  
 config.ShowEasing = EasingType.Swing;  
 config.CloseEasing = EasingType.Linear;  
 config.HideEasing = EasingType.Linear;  
 config.ShowMethod = AnimationMethod.SlideDown;  
 config.HideMethod = AnimationMethod.SlideUp;  
 config.CloseMethod = AnimationMethod.SlideUp;  
 config.PositionClass = NotificationPosition.TopRight;  
 config.PreventDuplicates = false;  
 config.ProgressBar = true;  
 config.NewestOnTop = false;  
 config.TimeOutInSecond = 5;  
});  
  
var app = builder.Build();  

app.UseNotification();

app.MapControllerRoute(  
 name: "default",  
 pattern: "{controller=Home}/{action=Index}/{id?}");  
  
app.Run();

Thank You!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published