Added the check to check the max user in add subscription as well
This commit is contained in:
parent
5d8a5909bc
commit
9765ce1b8f
@ -348,6 +348,8 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
// Calculate active/inactive employees count
|
// Calculate active/inactive employees count
|
||||||
var activeEmployeesCount = employees.Count(e => e.IsActive);
|
var activeEmployeesCount = employees.Count(e => e.IsActive);
|
||||||
var inActiveEmployeesCount = employees.Count - activeEmployeesCount;
|
var inActiveEmployeesCount = employees.Count - activeEmployeesCount;
|
||||||
|
var activeUserCount = employees.Count(e => e.IsActive && e.ApplicationUserId != null && e.Email != null);
|
||||||
|
|
||||||
|
|
||||||
// Filter current active (non-cancelled) subscription plan
|
// Filter current active (non-cancelled) subscription plan
|
||||||
var currentPlan = plans.FirstOrDefault(ts => !ts.IsCancelled);
|
var currentPlan = plans.FirstOrDefault(ts => !ts.IsCancelled);
|
||||||
@ -365,7 +367,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
response.OnHoldProjects = projects.Count(p => p.ProjectStatusId == projectOnHoldStatus);
|
response.OnHoldProjects = projects.Count(p => p.ProjectStatusId == projectOnHoldStatus);
|
||||||
response.InActiveProjects = projects.Count(p => p.ProjectStatusId == projectInActiveStatus);
|
response.InActiveProjects = projects.Count(p => p.ProjectStatusId == projectInActiveStatus);
|
||||||
response.CompletedProjects = projects.Count(p => p.ProjectStatusId == projectCompletedStatus);
|
response.CompletedProjects = projects.Count(p => p.ProjectStatusId == projectCompletedStatus);
|
||||||
response.SeatsAvailable = (int)(currentPlan?.MaxUsers ?? 1) - activeEmployeesCount;
|
response.SeatsAvailable = (int)(currentPlan?.MaxUsers ?? 1) - activeUserCount;
|
||||||
response.ExpiryDate = expiryDate;
|
response.ExpiryDate = expiryDate;
|
||||||
response.NextBillingDate = nextBillingDate;
|
response.NextBillingDate = nextBillingDate;
|
||||||
response.CreatedBy = createdBy;
|
response.CreatedBy = createdBy;
|
||||||
@ -900,7 +902,12 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
_logger.LogWarning("Subscription plan {PlanId} not found in database", model.PlanId);
|
_logger.LogWarning("Subscription plan {PlanId} not found in database", model.PlanId);
|
||||||
return NotFound(ApiResponse<object>.ErrorResponse("Subscription plan not found", "Subscription plan not found", 404));
|
return NotFound(ApiResponse<object>.ErrorResponse("Subscription plan not found", "Subscription plan not found", 404));
|
||||||
}
|
}
|
||||||
|
var activeUsers = await _context.Employees.CountAsync(e => e.Email != null && e.ApplicationUserId != null && e.TenantId == tenant.Id && e.IsActive);
|
||||||
|
if (activeUsers > model.MaxUsers)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Employee {EmployeeId} add less max user than the active user in the tenant {TenantId}", loggedInEmployee.Id, tenant.Id);
|
||||||
|
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid Max user count", "Max User count must be higher than active user count", 400));
|
||||||
|
}
|
||||||
await using var transaction = await _context.Database.BeginTransactionAsync();
|
await using var transaction = await _context.Database.BeginTransactionAsync();
|
||||||
var utcNow = DateTime.UtcNow;
|
var utcNow = DateTime.UtcNow;
|
||||||
|
|
||||||
@ -1146,9 +1153,8 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
var currentSubscription = currentSubscriptionTask.Result;
|
var currentSubscription = currentSubscriptionTask.Result;
|
||||||
var utcNow = DateTime.UtcNow;
|
var utcNow = DateTime.UtcNow;
|
||||||
|
|
||||||
var activeUsers = await context.Employees.CountAsync(e => e.Email != null && e.ApplicationUserId != null);
|
var activeUsers = await context.Employees.CountAsync(e => e.Email != null && e.ApplicationUserId != null && e.TenantId == tenant.Id && e.IsActive);
|
||||||
|
if (activeUsers > model.MaxUsers)
|
||||||
if (activeUsers < model.MaxUsers)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Employee {EmployeeId} add less max user than the active user in the tenant {TenantId}", loggedInEmployee.Id, tenant.Id);
|
_logger.LogWarning("Employee {EmployeeId} add less max user than the active user in the tenant {TenantId}", loggedInEmployee.Id, tenant.Id);
|
||||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid Max user count", "Max User count must be higher than active user count", 400));
|
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid Max user count", "Max User count must be higher than active user count", 400));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user