Skip to content

Commit

Permalink
Basic management of tags and categories
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Nov 28, 2023
1 parent 0a81354 commit fc96049
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private async Task RefreshListAsync()
//TODO: Refresh collection based on IDs
var categories = await _api.GetCategoriesAsync();
Categories.Clear();
Categories.AddRange(categories.Content!);
Categories.AddRange(categories.Content!.OrderBy(t => t.DisplayName));
}
catch (Exception ex)
{
Expand All @@ -68,6 +68,7 @@ private async Task AddCategoryAsync()
return;
}

using var loadingScope = _loadingIndicator.BeginLoading();
var apiResponse = await _api.AddCategoryAsync(new Category()
{
DisplayName = viewModel.Category.DisplayName,
Expand All @@ -91,6 +92,8 @@ private async Task UpdateCategoryAsync(Category? category)
RouteName = category.RouteName
});
var result = await _dialogService.ShowAsync(viewModel);

using var loadingScope = _loadingIndicator.BeginLoading();
if (result == ContentDialogResult.Primary)
{
var apiResponse = await _api.UpdateCategoryAsync(category.Id, new EditCategory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace MZikmund.ViewModels.Admin;

public class BlogPostsManagerViewModel : PageViewModel
{
public override string Title => Localizer.Instance.GetString("BlogPosts");
public override string Title => Localizer.Instance.GetString("Posts");
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private async Task RefreshListAsync()
//TODO: Refresh collection based on IDs
var tags = await _api.GetTagsAsync();
Tags.Clear();
Tags.AddRange(tags.Content!);
Tags.AddRange(tags.Content!.OrderBy(t => t.DisplayName));
}
catch (Exception ex)
{
Expand All @@ -68,6 +68,7 @@ private async Task AddTagAsync()
return;
}

using var loadingScope = _loadingIndicator.BeginLoading();
var apiResponse = await _api.AddTagAsync(new Tag()
{
DisplayName = viewModel.Tag.DisplayName,
Expand All @@ -91,6 +92,8 @@ private async Task UpdateTagAsync(Tag? tag)
RouteName = tag.RouteName
});
var result = await _dialogService.ShowAsync(viewModel);

using var loadingScope = _loadingIndicator.BeginLoading();
if (result == ContentDialogResult.Primary)
{
var apiResponse = await _api.UpdateTagAsync(tag.Id, new EditTag()
Expand Down
18 changes: 18 additions & 0 deletions src/web/MZikmund.Web.Core/Blog/DeleteTagHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using MediatR;
using MZikmund.Web.Data.Entities;
using MZikmund.Web.Data.Infrastructure;

namespace MZikmund.Web.Core.Blog;

public class DeleteTagHandler : IRequestHandler<DeleteTagCommand>
{
private readonly IRepository<TagEntity> _categoriesRepository;

public DeleteTagHandler(IRepository<TagEntity> categoriesRepository)
{
_categoriesRepository = categoriesRepository ?? throw new ArgumentNullException(nameof(categoriesRepository));
}

public async Task Handle(DeleteTagCommand request, CancellationToken cancellationToken) =>
await _categoriesRepository.DeleteAsync(request.TagId, cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Configure(EntityTypeBuilder<PostEntity> builder)
j => j
.HasOne(pt => pt.Category)
.WithMany()
.HasForeignKey(pt => pt.CategoryId),
.HasForeignKey(pt => pt.CategoryId), // TODO: Restrict delete
j => j
.HasOne(pt => pt.Post)
.WithMany()
Expand All @@ -35,7 +35,7 @@ public void Configure(EntityTypeBuilder<PostEntity> builder)
j => j
.HasOne(pt => pt.Tag)
.WithMany()
.HasForeignKey(pt => pt.TagId),
.HasForeignKey(pt => pt.TagId), // TODO: Restrict delete
j => j
.HasOne(pt => pt.Post)
.WithMany()
Expand Down

0 comments on commit fc96049

Please sign in to comment.