organization Tenant Mapping is already existed then return error message
This commit is contained in:
parent
1939a63d9a
commit
74dd9eeb8d
@ -722,31 +722,31 @@ 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)
|
||||||
{
|
|
||||||
// Create new tenant-organization mapping if none exists
|
|
||||||
var newMapping = new TenantOrgMapping
|
|
||||||
{
|
|
||||||
OrganizationId = organization.Id,
|
|
||||||
SPRID = organization.SPRID,
|
|
||||||
AssignedDate = DateTime.UtcNow,
|
|
||||||
IsActive = true,
|
|
||||||
AssignedById = loggedInEmployee.Id,
|
|
||||||
TenantId = tenantId
|
|
||||||
};
|
|
||||||
_context.TenantOrgMappings.Add(newMapping);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
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);
|
_logger.LogInfo("Organization {OrganizationId} is already assigned to tenant {TenantId}. No action taken.", organizationId, tenantId);
|
||||||
// Commit transaction anyway to complete scope cleanly (optional)
|
// Commit transaction anyway to complete scope cleanly (optional)
|
||||||
await transaction.CommitAsync();
|
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
|
||||||
|
{
|
||||||
|
OrganizationId = organization.Id,
|
||||||
|
SPRID = organization.SPRID,
|
||||||
|
AssignedDate = DateTime.UtcNow,
|
||||||
|
IsActive = true,
|
||||||
|
AssignedById = loggedInEmployee.Id,
|
||||||
|
TenantId = tenantId
|
||||||
|
};
|
||||||
|
_context.TenantOrgMappings.Add(newMapping);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
await transaction.CommitAsync();
|
||||||
|
|
||||||
|
_logger.LogInfo("Assigned organization {OrganizationId} to tenant {TenantId} successfully.", organizationId, tenantId);
|
||||||
|
|
||||||
|
|
||||||
// Prepare response view model
|
// Prepare response view model
|
||||||
var response = _mapper.Map<BasicOrganizationVm>(organization);
|
var response = _mapper.Map<BasicOrganizationVm>(organization);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user