public async Task <string> GenerateCode(string uniqueCode) { var result = await _repository.CodeExists(uniqueCode); if (result) { return(uniqueCode); } var code = CodeService.GenerateRandomCode(); var codes = await _repository.GetAllDatabaseUniqueCodes(); while (codes.Contains(code)) { code = CodeService.GenerateRandomCode(); } return(code); }