2020-05-03 17:42:01 -06:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-06-11 01:00:41 -05:00
|
|
|
|
using System.Reflection;
|
2020-05-03 17:42:01 -06:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-05-28 16:19:02 -05:00
|
|
|
|
using BTCPayServer.Data;
|
|
|
|
|
using BTCPayServer.Events;
|
|
|
|
|
using BTCPayServer.Events.Notifications;
|
|
|
|
|
using Newtonsoft.Json;
|
2020-05-03 17:42:01 -06:00
|
|
|
|
|
2020-05-27 18:35:25 -05:00
|
|
|
|
namespace BTCPayServer.Models.NotificationViewModels
|
2020-05-03 17:42:01 -06:00
|
|
|
|
{
|
|
|
|
|
public class IndexViewModel
|
|
|
|
|
{
|
2020-05-28 16:19:02 -05:00
|
|
|
|
public List<NotificationViewModel> Items { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class NotificationViewModel
|
|
|
|
|
{
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
public DateTimeOffset Created { get; set; }
|
|
|
|
|
public string Body { get; set; }
|
|
|
|
|
public string ActionLink { get; set; }
|
2020-05-28 22:57:18 -05:00
|
|
|
|
public bool Seen { get; set; }
|
2020-05-28 16:19:02 -05:00
|
|
|
|
}
|
2020-05-03 17:42:01 -06:00
|
|
|
|
|
2020-05-28 16:19:02 -05:00
|
|
|
|
public static class NotificationViewModelExt
|
|
|
|
|
{
|
|
|
|
|
public static NotificationViewModel ViewModel(this NotificationData data)
|
2020-05-03 17:42:01 -06:00
|
|
|
|
{
|
2020-06-11 01:00:41 -05:00
|
|
|
|
var baseType = typeof(NotificationEventBase);
|
2020-05-28 16:19:02 -05:00
|
|
|
|
|
2020-06-11 01:00:41 -05:00
|
|
|
|
var typeName = baseType.FullName.Replace(nameof(NotificationEventBase), data.NotificationType, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
var instance = Activator.CreateInstance(baseType.Assembly.GetType(typeName)) as NotificationEventBase;
|
2020-05-28 16:19:02 -05:00
|
|
|
|
|
2020-06-11 01:00:41 -05:00
|
|
|
|
return instance.ToViewModel(data);
|
2020-05-03 17:42:01 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|