@using BLAIzor.Models @using BLAIzor.Services @inject ContentEditorService contentEditorService @inject DialogService dialogService @inject NotificationService notificationService
Content count: @contentItems.Count
See all
@if (isVisible) { } @code { [Parameter] public int ContentGroupId { get; set; } [Parameter] public Func OnManageContentItemClicked { get; set; } private List contentItems = new(); private bool isVisible = false; protected override async Task OnInitializedAsync() { contentItems = await contentEditorService.GetContentItemsByGroupIdAsync(ContentGroupId); } private void ToggleVisibility() { isVisible = !isVisible; } private async Task CreateNewItem() { var newItem = new ContentItem { ContentGroupId = ContentGroupId, Title = "New Item", Description = "", Content = "", Language = "en", Tags = "", IsPublished = false, CreatedAt = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, Version = 1 }; var result = await contentEditorService.CreateContentItemAsync(newItem); if (result != null) { contentItems.Insert(0, result); } } private async Task EditItem(int itemId) { if (OnManageContentItemClicked != null) await OnManageContentItemClicked.Invoke("EditContentItem", itemId); } private async Task DeleteItem(int itemId) { var confirmationResult = await dialogService.Confirm("Are you sure?", "Delete content", new ConfirmOptions() { OkButtonText = "Delete", CancelButtonText = "Oops, no" }); if (confirmationResult == true) { await ReallyDeleteItem(itemId); } else { //do nothing? } } private async Task ReallyDeleteItem(int itemId) { var result = await contentEditorService.DeleteContentItemByIdAsync(itemId); if (result) { var toRemove = contentItems.FirstOrDefault(c => c.Id == itemId); if (toRemove != null) { contentItems.Remove(toRemove); } var message = NotificationHelper.CreateNotificationMessage("Group deleted", 2, "Success", "ContentGroup deleted"); ShowNotification(message); StateHasChanged(); } } public void ShowNotification(NotificationMessage message) { notificationService.Notify(message); } }