Skip to content

Commit

Permalink
Removed check if current employee is a dentist
Browse files Browse the repository at this point in the history
This check caused a bug, since the admin or superadmin must be a dentist in order to assign one or more specialties to the employee.

This commit relates to issue #124
  • Loading branch information
MrDave1999 committed Dec 29, 2022
1 parent 9131c47 commit 8421b9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
26 changes: 12 additions & 14 deletions src/Features/Employees/EmployeeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public EmployeeService(IUnitOfWork unitOfWork, IPasswordHasher passwordHasher)
}

public Task<IEnumerable<EmployeeGetDto>> GetEmployeesAsync(ClaimsPrincipal currentEmployee)
=> currentEmployee.IsAdmin()
=> currentEmployee.IsAdmin()
? _unitOfWork.EmployeeRepository.GetFullEmployeesProfileByOfficeIdAsync(currentEmployee.GetEmployeeId(), currentEmployee.GetOfficeId())
: _unitOfWork.EmployeeRepository.GetFullEmployeesProfileAsync();

Expand Down Expand Up @@ -73,20 +73,18 @@ public async Task<Response> EditProfileByAdminAsync(int employeeId, ClaimsPrinci

if (employeeUpdateDto.Password is not null)
employeeToEdit.User.Password = _passwordHasher.HashPassword(employeeUpdateDto.Password);

employeeUpdateDto.MapToEmployee(employeeToEdit);

if (currentEmployee.IsDentist())
{
var specialtiesId = employeeUpdateDto.SpecialtiesId ?? Enumerable.Empty<int>().ToList();
_unitOfWork.EmployeeSpecialtyRepository.UpdateEmployeeSpecialties(employeeToEdit.Id,
employeeToEdit.EmployeeSpecialties,
specialtiesId);
}

_unitOfWork.UserRoleRepository.UpdateUserRoles(employeeToEdit.UserId,
employeeToEdit.User.UserRoles,
rolesId: employeeUpdateDto.Roles);
employeeUpdateDto.MapToEmployee(employeeToEdit);
var specialtiesId = employeeUpdateDto.SpecialtiesId ?? Enumerable.Empty<int>().ToList();
_unitOfWork.EmployeeSpecialtyRepository
.UpdateEmployeeSpecialties(employeeToEdit.Id,
employeeToEdit.EmployeeSpecialties,
specialtiesId);

_unitOfWork.UserRoleRepository
.UpdateUserRoles(employeeToEdit.UserId,
employeeToEdit.User.UserRoles,
rolesId: employeeUpdateDto.Roles);
await _unitOfWork.SaveChangesAsync();

return new Response
Expand Down
17 changes: 7 additions & 10 deletions src/Features/UserRegistration/UserRegisterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class UserRegisterService : IUserRegisterService
private readonly ITokenService _tokenService;
private readonly IPasswordHasher _passwordHasher;

public UserRegisterService(IUnitOfWork unitOfWork,
IEmailService emailService,
public UserRegisterService(IUnitOfWork unitOfWork,
IEmailService emailService,
ITokenService tokenService,
IPasswordHasher passwordHasher)
{
Expand Down Expand Up @@ -69,15 +69,12 @@ public async Task<Response<DtoBase>> CreateEmployeeAccountAsync(ClaimsPrincipal
_unitOfWork.EmployeeRepository.Insert(employee);
employee.User = user;
employee.Person = user.Person;
if (currentEmployee.IsDentist())
var specialtiesId = (employeeInsertDto.SpecialtiesId ?? Enumerable.Empty<int>()).RemoveDuplicates();
foreach (var specialtyId in specialtiesId)
{
var specialtiesId = (employeeInsertDto.SpecialtiesId ?? Enumerable.Empty<int>()).RemoveDuplicates();
foreach (var specialtyId in specialtiesId)
{
var employeeSpecialty = new EmployeeSpecialty { SpecialtyId = specialtyId };
_unitOfWork.EmployeeSpecialtyRepository.Insert(employeeSpecialty);
employeeSpecialty.Employee = employee;
}
var employeeSpecialty = new EmployeeSpecialty { SpecialtyId = specialtyId };
_unitOfWork.EmployeeSpecialtyRepository.Insert(employeeSpecialty);
employeeSpecialty.Employee = employee;
}
await _unitOfWork.SaveChangesAsync();

Expand Down

0 comments on commit 8421b9e

Please sign in to comment.