Created a new API to delete tenant
This commit is contained in:
parent
dca6414a59
commit
a70c3007f1
@ -55,7 +55,6 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
Description = settings.JobRoleDescription,
|
Description = settings.JobRoleDescription,
|
||||||
TenantId = TenantId
|
TenantId = TenantId
|
||||||
};
|
};
|
||||||
var existingJobRole = await _context.JobRoles.AsNoTracking().FirstOrDefaultAsync(r => r.Name == settings.JobRoleName);
|
|
||||||
|
|
||||||
ApplicationRole role = new ApplicationRole
|
ApplicationRole role = new ApplicationRole
|
||||||
{
|
{
|
||||||
@ -63,27 +62,10 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
Description = settings.RoleDescription,
|
Description = settings.RoleDescription,
|
||||||
TenantId = TenantId
|
TenantId = TenantId
|
||||||
};
|
};
|
||||||
var existingRole = await _context.ApplicationRoles.AsNoTracking().FirstOrDefaultAsync(r => r.Role == settings.RoleName);
|
|
||||||
|
|
||||||
if (existingJobRole == null)
|
|
||||||
{
|
|
||||||
_context.JobRoles.Add(jobRole);
|
_context.JobRoles.Add(jobRole);
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
jobRole = existingJobRole;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existingRole == null)
|
|
||||||
{
|
|
||||||
_context.ApplicationRoles.Add(role);
|
_context.ApplicationRoles.Add(role);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
role = existingRole;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<FeaturePermission> permissions = await _context.FeaturePermissions.AsNoTracking().ToListAsync();
|
List<FeaturePermission> permissions = await _context.FeaturePermissions.AsNoTracking().ToListAsync();
|
||||||
List<RolePermissionMappings> rolePermissionMappings = new List<RolePermissionMappings>();
|
List<RolePermissionMappings> rolePermissionMappings = new List<RolePermissionMappings>();
|
||||||
@ -140,6 +122,29 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
return BadRequest("Falied to create Tenant");
|
return BadRequest("Falied to create Tenant");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
[HttpDelete("suspend/{tenantId}")]
|
||||||
|
public async Task<IActionResult> SuspendTenant(int tenantId)
|
||||||
|
{
|
||||||
|
if (tenantId <= 0)
|
||||||
|
{
|
||||||
|
return BadRequest("Tenant Id is required and must be greater than zero.");
|
||||||
|
}
|
||||||
|
var tenant = await _context.Tenants.FirstOrDefaultAsync(t => t.Id == tenantId);
|
||||||
|
var user = await _context.ApplicationUsers.FirstOrDefaultAsync(u => u.TenantId == tenantId && u.IsRootUser == true);
|
||||||
|
var employee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == tenantId && e.ApplicationUserId == user.Id);
|
||||||
|
if (tenant == null && user == null)
|
||||||
|
{
|
||||||
|
return NotFound("Tenant Not Found");
|
||||||
|
}
|
||||||
|
|
||||||
|
//tenant.IsActive = false; // Uncomment it after Adding isActive property in tenant
|
||||||
|
//_context.Tenants.Add(tenant);
|
||||||
|
|
||||||
|
employee.IsActive = false;
|
||||||
|
_context.Employees.Add(employee);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return Ok("Tenant is Suspended");
|
||||||
|
}
|
||||||
private static Employee CreateTenantDtoToEmployee(CreateTenantDto model, int TenantId, string? ApplicationUserId,int jobRoleId)
|
private static Employee CreateTenantDtoToEmployee(CreateTenantDto model, int TenantId, string? ApplicationUserId,int jobRoleId)
|
||||||
{
|
{
|
||||||
return new Employee
|
return new Employee
|
||||||
|
Loading…
x
Reference in New Issue
Block a user