Add category catalog management
This commit is contained in:
1 parent
b1e0638979
commit
28fc49ea39
4 files changed
+185
-11
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using System.Data;
|
||||
using Helpdesk.Application.Abstractions;
|
||||
using Helpdesk.Application.Common;
|
||||
using Helpdesk.Application.Statistics;
|
||||
using Helpdesk.Domain.Auth;
|
||||
using Helpdesk.Domain.Catalogs;
|
||||
@@ -11,6 +12,7 @@ using Helpdesk.Infrastructure.Security;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace Helpdesk.Infrastructure.Persistence;
|
||||
|
||||
@@ -38,6 +40,20 @@ public sealed class HelpdeskDbContext(DbContextOptions<HelpdeskDbContext> option
|
||||
public DbSet<NotificationDelivery> NotificationDeliveries => Set<NotificationDelivery>();
|
||||
public DbSet<PushDevice> PushDevices => Set<PushDevice>();
|
||||
|
||||
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await base.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
catch (DbUpdateException exception) when (
|
||||
exception.InnerException is MySqlException { ErrorCode: MySqlErrorCode.DuplicateKeyEntry } &&
|
||||
exception.Entries is [var entry] && entry.Entity is (IssueCategory or ProposalCategory))
|
||||
{
|
||||
throw new ConflictException("Kategorie se stejným názvem již existuje.");
|
||||
}
|
||||
}
|
||||
|
||||
public Task<IDbContextTransaction> BeginProposalWriteAsync(CancellationToken ct) =>
|
||||
Database.BeginTransactionAsync(IsolationLevel.ReadCommitted, ct);
|
||||
|
||||
|
||||
Reference in new issue
Block a user