Sprint 5 #28
11
MainProject/Models/Api/Common/Exceptions/CreateException.cs
Normal file
11
MainProject/Models/Api/Common/Exceptions/CreateException.cs
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
11
MainProject/Models/Api/Common/Exceptions/UpdateException.cs
Normal file
11
MainProject/Models/Api/Common/Exceptions/UpdateException.cs
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user