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 + { + + + Name + + + + + + Description + + + + + + + @foreach (var limitPart in Limits.Chunk(3)) + { + + @foreach (var limit in limitPart) + { + + + + Identifier + + + + + + Amount + + + + + + + Options + + + + + + limit.Options.Add(new())" type="button" class="btn btn-light-primary me-auto">Add option + Limits.Remove(limit)" class="btn btn-danger float-end"> + + + + + + + } + + } + + + + Limits.Add(new())" class="btn btn-primary"> + Add new limit + + + Save subscription + + + + } + + + + +@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