btcpayserver/BTCPayServer/Models/NotificationViewModels/IndexViewModel.cs

52 lines
1.5 KiB
C#
Raw Normal View History

2020-05-03 17:42:01 -06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
2020-05-03 17:42:01 -06:00
using System.Text;
using System.Threading.Tasks;
using BTCPayServer.Data;
using BTCPayServer.Events;
using BTCPayServer.Events.Notifications;
using Newtonsoft.Json;
2020-05-03 17:42:01 -06:00
namespace BTCPayServer.Models.NotificationViewModels
2020-05-03 17:42:01 -06:00
{
public class IndexViewModel
{
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-03 17:42:01 -06:00
public static class NotificationViewModelExt
{
public static NotificationViewModel ViewModel(this NotificationData data)
2020-05-03 17:42:01 -06:00
{
var baseType = typeof(NotificationBase);
var fullTypeName = baseType.FullName.Replace(nameof(NotificationBase), data.NotificationType, StringComparison.OrdinalIgnoreCase);
var parsedType = baseType.Assembly.GetType(fullTypeName);
var instance = Activator.CreateInstance(parsedType) as NotificationBase;
var casted = JsonConvert.DeserializeObject(ZipUtils.Unzip(data.Blob), parsedType);
var obj = new NotificationViewModel
{
Id = data.Id,
Created = data.Created,
Seen = data.Seen
};
instance.FillViewModel(obj);
return obj;
2020-05-03 17:42:01 -06:00
}
}
}