more friendly

This commit is contained in:
2017-09-24 23:42:41 +02:00
parent 68c8ff2a58
commit 109aa1bc55
11 changed files with 763 additions and 264 deletions

View File

@ -0,0 +1,35 @@
using System.Collections.Generic;
using Microsoft.AspNet.Mvc;
using Yavsc.Models.Messaging;
namespace Yavsc.Helpers
{
public static class ControllerHelpers
{
public static void NotifyWarning(this Controller controller, string title, string body)
{
var notifs = SetupNotificationList(controller);
notifs.Add(new Notification { title = title, body = body });
}
public static void NotifyInfo(this Controller controller, string title, string body)
{
var notifs = SetupNotificationList(controller);
notifs.Add(new Notification { title = title, body = body });
}
public static void Notify(this Controller controller, IEnumerable<Notification> notes)
{
var notifs = SetupNotificationList(controller);
notifs.AddRange(notes);
}
private static List<Notification> SetupNotificationList(this Controller controller)
{
List<Notification> notifs = (List<Notification>)controller.ViewData["Notify"];
if (notifs == null)
{
controller.ViewData["Notify"] = notifs = new List<Notification>();
}
return notifs;
}
}
}