organization Tenant Mapping is already existed then return error message
This commit is contained in:
parent
1939a63d9a
commit
74dd9eeb8d
@ -722,8 +722,14 @@ namespace Marco.Pms.Services.Controllers
|
||||
return NotFound(ApiResponse<object>.ErrorResponse("Organization not found", "Organization not found in database", 404));
|
||||
}
|
||||
|
||||
if (organizationTenantMapping == null)
|
||||
if (organizationTenantMapping != null)
|
||||
{
|
||||
_logger.LogInfo("Organization {OrganizationId} is already assigned to tenant {TenantId}. No action taken.", organizationId, tenantId);
|
||||
// Commit transaction anyway to complete scope cleanly (optional)
|
||||
await transaction.RollbackAsync();
|
||||
return StatusCode(409, ApiResponse<object>.ErrorResponse("Organization is already assigned to tenant", "Organization is already assigned to tenant", 409));
|
||||
}
|
||||
|
||||
// Create new tenant-organization mapping if none exists
|
||||
var newMapping = new TenantOrgMapping
|
||||
{
|
||||
@ -739,13 +745,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
await transaction.CommitAsync();
|
||||
|
||||
_logger.LogInfo("Assigned organization {OrganizationId} to tenant {TenantId} successfully.", organizationId, tenantId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInfo("Organization {OrganizationId} is already assigned to tenant {TenantId}. No action taken.", organizationId, tenantId);
|
||||
// Commit transaction anyway to complete scope cleanly (optional)
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
|
||||
|
||||
// Prepare response view model
|
||||
var response = _mapper.Map<BasicOrganizationVm>(organization);
|
||||
|
Loading…
x
Reference in New Issue
Block a user