Added functionality to remove entries from the employee-role mapping when IsEnabled is set to false.

This commit is contained in:
ashutosh.nehete 2025-04-26 19:06:45 +05:30
parent 4ec27709c9
commit 512a899310

View File

@ -32,7 +32,7 @@ namespace MarcoBMS.Services.Controllers
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
public EmployeeController(UserManager<IdentityUser> userManager, IEmailSender emailSender, public EmployeeController(UserManager<IdentityUser> userManager, IEmailSender emailSender,
ApplicationDbContext context, EmployeeHelper employeeHelper, UserHelper userHelper, IConfiguration configuration) ApplicationDbContext context, EmployeeHelper employeeHelper, UserHelper userHelper, IConfiguration configuration)
{ {
_context = context; _context = context;
@ -109,10 +109,11 @@ namespace MarcoBMS.Services.Controllers
_context.EmployeeRoleMappings.Add(mapping); _context.EmployeeRoleMappings.Add(mapping);
} }
else else if (role.IsEnabled == false)
{ {
_context.EmployeeRoleMappings.Update(mapping); _context.EmployeeRoleMappings.Remove(existingItem);
} }
} }
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
} }
@ -296,7 +297,7 @@ namespace MarcoBMS.Services.Controllers
else else
{ {
// Create Employee record if missing // Create Employee record if missing
Employee newEmployee = GetNewEmployeeModel(model, TenantId, null); Employee newEmployee = GetNewEmployeeModel(model, TenantId, null);
_context.Employees.Add(newEmployee); _context.Employees.Add(newEmployee);
} }
@ -304,7 +305,7 @@ namespace MarcoBMS.Services.Controllers
responsemessage = "User created successfully."; responsemessage = "User created successfully.";
} }
return Ok(ApiResponse<object>.SuccessResponse("Success.",responsemessage, 200)); return Ok(ApiResponse<object>.SuccessResponse("Success.", responsemessage, 200));
} }
#nullable disable #nullable disable
private static Employee GetNewEmployeeModel(CreateUserDto model, int TenantId, string ApplicationUserId) private static Employee GetNewEmployeeModel(CreateUserDto model, int TenantId, string ApplicationUserId)