Files
btcpayserver/BTCPayServer/Models/AppViewModels/CreateAppViewModel.cs
Andrew Camilleri f74ea14d8b Plugins can now build apps (#4608)
* Plugins can now build apps

* fix tests

* fixup

* pluginize existing apps

* Test fixes part 1

* Test fixes part 2

* Fix Crowdfund namespace

* Syntax

* More namespace fixes

* Markup

* Test fix

* upstream fixes

* Add plugin icon

* Fix nullable build warnings

* allow pre popualting app creation

* Fixes after merge

* Make link methods async

* Use AppData as parameter for ConfigureLink

* GetApps by AppType

* Use ConfigureLink on dashboard

* Rename method

* Add properties to indicate stats support

* Property updates

* Test fixes

* Clean up imports

* Fixes after merge

---------

Co-authored-by: Dennis Reimann <mail@dennisreimann.de>
2023-03-17 11:56:32 +09:00

47 lines
1.4 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.Linq;
using BTCPayServer.Plugins.PointOfSale;
using BTCPayServer.Services.Apps;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace BTCPayServer.Models.AppViewModels
{
public class CreateAppViewModel
{
public CreateAppViewModel()
{
}
public CreateAppViewModel(AppService appService)
{
SetApps(appService);
}
[Required]
[MaxLength(50)]
[MinLength(1)]
[Display(Name = "App Name")]
public string AppName { get; set; }
[Display(Name = "Store")]
public string StoreId { get; set; }
[Display(Name = "App Type")]
public string SelectedAppType { get; set; }
public SelectList AppTypes { get; set; }
private void SetApps(AppService appService)
{
var defaultAppType = PointOfSaleApp.AppType;
var choices = appService.GetAvailableAppTypes().Select(pair =>
new SelectListItem(pair.Value, pair.Key, pair.Key == defaultAppType));
var chosen = choices.FirstOrDefault(f => f.Value == defaultAppType) ?? choices.FirstOrDefault();
AppTypes = new SelectList(choices, nameof(chosen.Value), nameof(chosen.Text), chosen);
SelectedAppType = chosen.Value;
}
}
}