mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-03 17:36:59 +01:00
Refactoring conversion of data to view model, switching to FillViewModel
This commit is contained in:
parent
ffa04b625a
commit
07efa87fe5
3 changed files with 18 additions and 16 deletions
|
@ -10,19 +10,10 @@ namespace BTCPayServer.Events.Notifications
|
||||||
|
|
||||||
public string Version { get; set; }
|
public string Version { get; set; }
|
||||||
|
|
||||||
public override NotificationViewModel ToViewModel(NotificationData data)
|
public override void FillViewModel(NotificationViewModel vm)
|
||||||
{
|
{
|
||||||
var casted = JsonConvert.DeserializeObject<NewVersionNotification>(ZipUtils.Unzip(data.Blob));
|
vm.Body = $"New version {Version} released!";
|
||||||
var obj = new NotificationViewModel
|
vm.ActionLink = $"https://github.com/btcpayserver/btcpayserver/releases/tag/v{Version}";
|
||||||
{
|
|
||||||
Id = data.Id,
|
|
||||||
Created = data.Created,
|
|
||||||
Body = $"New version {casted.Version} released!",
|
|
||||||
ActionLink = "https://github.com/btcpayserver/btcpayserver/releases/tag/v" + casted.Version,
|
|
||||||
Seen = data.Seen
|
|
||||||
};
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,6 @@ namespace BTCPayServer.Events.Notifications
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract NotificationViewModel ToViewModel(NotificationData data);
|
public abstract void FillViewModel(NotificationViewModel data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,21 @@ namespace BTCPayServer.Models.NotificationViewModels
|
||||||
{
|
{
|
||||||
var baseType = typeof(NotificationBase);
|
var baseType = typeof(NotificationBase);
|
||||||
|
|
||||||
var typeName = baseType.FullName.Replace(nameof(NotificationBase), data.NotificationType, StringComparison.OrdinalIgnoreCase);
|
var fullTypeName = baseType.FullName.Replace(nameof(NotificationBase), data.NotificationType, StringComparison.OrdinalIgnoreCase);
|
||||||
var instance = Activator.CreateInstance(baseType.Assembly.GetType(typeName)) as NotificationBase;
|
var parsedType = baseType.Assembly.GetType(fullTypeName);
|
||||||
|
var instance = Activator.CreateInstance(parsedType) as NotificationBase;
|
||||||
|
|
||||||
return instance.ToViewModel(data);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue