LANCommander/LANCommander.Server/Controllers/_BaseController.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2024-10-07 18:38:27 -05:00
using LANCommander.Server.Services;
using LANCommander.Server.Services.Models;
2024-08-28 20:44:14 -05:00
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
2024-08-04 18:44:33 -05:00
namespace LANCommander.Server.Controllers
{
public abstract class BaseController : Controller
{
protected readonly ILogger Logger;
2024-10-07 18:38:27 -05:00
protected readonly Settings Settings;
public BaseController(ILogger logger)
{
Logger = logger;
2024-08-28 20:44:14 -05:00
Settings = SettingService.GetSettings();
}
protected void Alert(string message, string type = "info", bool dismissable = true)
{
List<AlertViewModel> alerts;
try
{
alerts = JsonSerializer.Deserialize<List<AlertViewModel>>((string)TempData["Alerts"]);
}
catch
{
alerts = new List<AlertViewModel>();
}
alerts.Add(new AlertViewModel()
{
Message = message,
Type = type,
Dismissable = dismissable
});
TempData["Alerts"] = JsonSerializer.Serialize(alerts);
}
}
}