Sprint 5 #28

Merged
csimonapastore merged 28 commits from sprints/5 into main 2025-05-28 00:10:39 +02:00
4 changed files with 35 additions and 6 deletions
Showing only changes of commit b778a357ba - Show all commits

View File

@@ -0,0 +1,11 @@
using System;
namespace BasicDotnetTemplate.MainProject.Models.Api.Common.Exceptions;
public class CreateException : Exception
{
public CreateException(string message, Exception innerException)
: base(message, innerException)
{
}
}

View File

@@ -0,0 +1,11 @@
using System;
namespace BasicDotnetTemplate.MainProject.Models.Api.Common.Exceptions;
public class UpdateException : Exception
{
public UpdateException(string message, Exception innerException)
: base(message, innerException)
{
}
}

View File

@@ -1,6 +1,7 @@
using System.Collections;
using BasicDotnetTemplate.MainProject.Core.Database;
using BasicDotnetTemplate.MainProject.Models.Api.Common.Exceptions;
using BasicDotnetTemplate.MainProject.Models.Api.Data.Role;
using BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
using Microsoft.EntityFrameworkCore;
@@ -20,6 +21,7 @@ public interface IRoleService
public class RoleService : BaseService, IRoleService
{
private readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
public RoleService(
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration,
@@ -103,10 +105,11 @@ public class RoleService : BaseService, IRoleService
await transaction.CommitAsync();
role = tempRole;
}
catch (Exception)
catch (Exception exception)
{
await transaction.RollbackAsync();
throw;
Logger.Error(exception, $"[RoleService][CreateRoleAsync]");
throw new CreateException($"An error occurred while saving the role for transaction ID {transaction.TransactionId}.", exception);
}
return role;
@@ -130,10 +133,11 @@ public class RoleService : BaseService, IRoleService
await _sqlServerContext.SaveChangesAsync();
await transaction.CommitAsync();
}
catch (Exception)
catch (Exception exception)
{
Logger.Error(exception, $"[RoleService][UpdateRoleAsync] | {transaction.TransactionId}");
await transaction.RollbackAsync();
throw;
throw new UpdateException($"An error occurred while updating the role for transaction ID {transaction.TransactionId}.", exception);
}
return role;

View File

@@ -1,6 +1,7 @@
using System.Collections;
using BasicDotnetTemplate.MainProject.Core.Database;
using BasicDotnetTemplate.MainProject.Models.Api.Common.Exceptions;
using BasicDotnetTemplate.MainProject.Models.Api.Data.User;
using BasicDotnetTemplate.MainProject.Models.Database.SqlServer;
using Microsoft.EntityFrameworkCore;
@@ -19,6 +20,7 @@ public interface IUserService
public class UserService : BaseService, IUserService
{
private readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
public UserService(
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration,
@@ -115,10 +117,11 @@ public class UserService : BaseService, IUserService
await transaction.CommitAsync();
user = tempUser;
}
catch (Exception)
catch (Exception exception)
{
await transaction.RollbackAsync();
throw;
Logger.Error(exception, $"[UserService][CreateUserAsync]");
throw new CreateException($"An error occurred while creating the user for transaction ID {transaction.TransactionId}.", exception);
}