organization Tenant Mapping is already existed then return error message

This commit is contained in:
ashutosh.nehete 2025-10-10 17:53:23 +05:30
parent 1939a63d9a
commit 74dd9eeb8d

View File

@ -722,8 +722,14 @@ namespace Marco.Pms.Services.Controllers
return NotFound(ApiResponse<object>.ErrorResponse("Organization not found", "Organization not found in database", 404)); 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 // Create new tenant-organization mapping if none exists
var newMapping = new TenantOrgMapping var newMapping = new TenantOrgMapping
{ {
@ -739,13 +745,7 @@ namespace Marco.Pms.Services.Controllers
await transaction.CommitAsync(); await transaction.CommitAsync();
_logger.LogInfo("Assigned organization {OrganizationId} to tenant {TenantId} successfully.", organizationId, tenantId); _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 // Prepare response view model
var response = _mapper.Map<BasicOrganizationVm>(organization); var response = _mapper.Map<BasicOrganizationVm>(organization);