From a41a929e7f9f365e6eff6cf8f1b82967dd656222 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Mon, 3 Apr 2023 19:45:01 +0200 Subject: [PATCH] Added subscription edit --- .../Views/Admin/Subscriptions/Edit.razor | 168 ++++++++++++++++++ Moonlight/resources/lang/de_de.lang | 1 + 2 files changed, 169 insertions(+) create mode 100644 Moonlight/Shared/Views/Admin/Subscriptions/Edit.razor diff --git a/Moonlight/Shared/Views/Admin/Subscriptions/Edit.razor b/Moonlight/Shared/Views/Admin/Subscriptions/Edit.razor new file mode 100644 index 00000000..87dd733c --- /dev/null +++ b/Moonlight/Shared/Views/Admin/Subscriptions/Edit.razor @@ -0,0 +1,168 @@ +@page "/admin/subscriptions/edit/{Id:int}" +@using Moonlight.App.Models.Forms +@using Moonlight.App.Models.Misc +@using Moonlight.App.Repositories +@using Moonlight.App.Services +@using Moonlight.App.Database.Entities + +@inject NavigationManager NavigationManager +@inject SubscriptionRepository SubscriptionRepository +@inject SubscriptionAdminService SubscriptionAdminService + + +
+ + @if (Subscription == null) + { +
+ No subscription with this id has been found +
+ } + else + { + + +
+ +
+ +
+ +
+ +
+ @foreach (var limitPart in Limits.Chunk(3)) + { +
+ @foreach (var limit in limitPart) + { +
+
+ +
+ +
+ +
+ +
+
+
+ Options +
+
+ +
+
+ + +
+
+
+
+ } +
+ } +
+ +
+ + +
+
+ } +
+
+
+ +@code +{ + [Parameter] + public int Id { get; set; } + + private Subscription? Subscription; + + private SubscriptionDataModel Model = new(); + private List Limits = new(); + + private async Task OnSubmit() + { + Subscription!.Name = Model.Name; + Subscription.Description = Model.Description; + + SubscriptionRepository.Update(Subscription); + + await SubscriptionAdminService.SaveLimits(Subscription, Limits.ToArray()); + + NavigationManager.NavigateTo("/admin/subscriptions"); + } + + private async Task Load(LazyLoader arg) + { + Subscription = SubscriptionRepository + .Get() + .FirstOrDefault(x => x.Id == Id); + + if (Subscription != null) + { + Model.Name = Subscription.Name; + Model.Description = Subscription.Description; + + Limits = (await SubscriptionAdminService.GetLimits(Subscription)).ToList(); + } + } +} \ No newline at end of file diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index 0cfc0d21..b56f294a 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -462,3 +462,4 @@ Create subscription;Create subscription Options;Options Amount;Amount Do you really want to delete it?;Do you really want to delete it? +Save subscription;Save subscription