private void ValidateReceptionist(ReceptionistDto receptionistDto, long adminId) { if (string.IsNullOrEmpty(receptionistDto.UserName)) { throw new ValidationException(ErrorCodes.EmptyUserName); } if (receptionistDto.UserName.Length > 100) { throw new ValidationException(ErrorCodes.NameExceedLength); } if (string.IsNullOrEmpty(receptionistDto.Password)) { throw new ValidationException(ErrorCodes.EmptyPassword); } if (receptionistDto.Password.Length < 8 || receptionistDto.Password.Length > 25) { throw new ValidationException(ErrorCodes.PasswordLengthNotMatched); } if (_supervisorService.CheckUserNameDuplicated(receptionistDto.UserName, receptionistDto.UserId, adminId)) { throw new ValidationException(ErrorCodes.UserNameAlreadyExist); } if (_receptionistService.CheckUserNameDuplicated(receptionistDto.UserName, receptionistDto.UserId, adminId)) { throw new ValidationException(ErrorCodes.UserNameAlreadyExist); } if (_roomService.CheckUserNameDuplicated(receptionistDto.UserName, receptionistDto.UserId, adminId)) { throw new ValidationException(ErrorCodes.UserNameAlreadyExist); } }
public void UpdateReceptionist(ReceptionistDto receptionistDto, long adminId) { var receptionist = _receptionistService.Find(receptionistDto.UserId); if (receptionist == null) { throw new NotFoundException(ErrorCodes.UserNotFound); } ValidateReceptionist(receptionistDto, adminId); receptionist.UserName = receptionistDto.UserName; receptionist.Password = PasswordHelper.Encrypt(receptionistDto.Password); _receptionistService.Update(receptionist); SaveChanges(); }
public void AddReceptionist(ReceptionistDto receptionistDto, long adminId) { ValidateReceptionist(receptionistDto, adminId); var user = _UserService.Find(adminId); if (user == null) { throw new NotFoundException(ErrorCodes.UserNotFound); } Receptionist receptionist = Mapper.Map <Receptionist>(receptionistDto); receptionist.AdminId = adminId; receptionist.Password = PasswordHelper.Encrypt(receptionistDto.Password); receptionist.Role = Enums.RoleType.Receptionist; receptionist.IsActive = true; _receptionistService.Insert(receptionist); SaveChanges(); }