2018-04-03 11:50:41 +09:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Linq;
|
2023-03-17 03:56:32 +01:00
|
|
|
using BTCPayServer.Plugins.PointOfSale;
|
2018-04-03 11:50:41 +09:00
|
|
|
using BTCPayServer.Services.Apps;
|
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Models.AppViewModels
|
|
|
|
{
|
|
|
|
public class CreateAppViewModel
|
|
|
|
{
|
|
|
|
public CreateAppViewModel()
|
|
|
|
{
|
|
|
|
}
|
2023-03-17 03:56:32 +01:00
|
|
|
|
|
|
|
public CreateAppViewModel(AppService appService)
|
2018-04-03 11:50:41 +09:00
|
|
|
{
|
2023-03-17 03:56:32 +01:00
|
|
|
SetApps(appService);
|
2018-04-03 11:50:41 +09:00
|
|
|
}
|
2023-03-17 03:56:32 +01:00
|
|
|
|
2018-04-03 11:50:41 +09:00
|
|
|
[Required]
|
|
|
|
[MaxLength(50)]
|
|
|
|
[MinLength(1)]
|
2021-11-08 05:24:28 -08:00
|
|
|
[Display(Name = "App Name")]
|
2021-10-29 06:29:02 -04:00
|
|
|
public string AppName { get; set; }
|
2018-04-03 11:50:41 +09:00
|
|
|
|
|
|
|
[Display(Name = "Store")]
|
2021-12-11 04:32:23 +01:00
|
|
|
public string StoreId { get; set; }
|
2018-04-03 11:50:41 +09:00
|
|
|
|
2021-11-08 05:24:28 -08:00
|
|
|
[Display(Name = "App Type")]
|
2018-04-03 11:50:41 +09:00
|
|
|
public string SelectedAppType { get; set; }
|
|
|
|
|
|
|
|
public SelectList AppTypes { get; set; }
|
|
|
|
|
2023-03-17 03:56:32 +01:00
|
|
|
private void SetApps(AppService appService)
|
2018-04-03 11:50:41 +09:00
|
|
|
{
|
2023-03-20 10:39:26 +09:00
|
|
|
var defaultAppType = PointOfSaleAppType.AppType;
|
2023-03-17 03:56:32 +01:00
|
|
|
var choices = appService.GetAvailableAppTypes().Select(pair =>
|
|
|
|
new SelectListItem(pair.Value, pair.Key, pair.Key == defaultAppType));
|
|
|
|
|
2018-04-03 11:50:41 +09:00
|
|
|
var chosen = choices.FirstOrDefault(f => f.Value == defaultAppType) ?? choices.FirstOrDefault();
|
2023-03-17 03:56:32 +01:00
|
|
|
AppTypes = new SelectList(choices, nameof(chosen.Value), nameof(chosen.Text), chosen);
|
2018-04-03 11:50:41 +09:00
|
|
|
SelectedAppType = chosen.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|