Created a new API to delete tenant

This commit is contained in:
unknown 2025-03-29 15:33:12 +05:30 committed by Vikas Nale
parent 053391ae44
commit 24c283559f
2 changed files with 24 additions and 5 deletions

View File

@ -167,6 +167,30 @@ namespace Marco.Pms.Services.Controllers
return Ok(ApiResponse<object>.SuccessResponse(tenantVM, "Tenant Profile.", 200));
}
[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)
{
return new Employee

View File

@ -167,13 +167,8 @@ app.UseCors("Policy");
app.UseStaticFiles(); // Enables serving static files
<<<<<<< HEAD
//app.UseSerilogRequestLogging(); // This is Default Serilog Logging Middleware we are not using this because we're using custom logging middleware
=======
//app.UseSerilogRequestLogging(); // Log HTTP requests
>>>>>>> a4156153ff6618675abf0590395745816019a973
app.UseHttpsRedirection();
app.UseMiddleware<ExceptionHandlingMiddleware>();
app.UseMiddleware<TenantMiddleware>();