Advertisement
Guest User

Untitled

a guest
May 24th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public static Item GetFallbackItem(this Item item)
  2. {
  3. Assert.IsNotNull(item, "item cannot be null");
  4.  
  5. var success = false;
  6. int iterations = 0, maxIterations = 5;
  7. while (iterations++ < maxIterations)
  8. {
  9. var fallbackLang = item.Language.GetFallbackLanguage(item.Database);
  10. if (fallbackLang != null &&
  11. !fallbackLang.Name.IsNullOrEmpty() &&
  12. !fallbackLang.Equals(item.Language))
  13. {
  14. item = item.Database.GetItem(item.ID, fallbackLang, Version.Latest);
  15. if (item != null && item.Versions.Count > 0)
  16. {
  17. success = true;
  18. break;
  19. }
  20. }
  21. }
  22.  
  23. return success ? item : null;
  24. }
  25.  
  26. public static bool HasFallbackVersion(this Item item)
  27. {
  28. if (item.Versions.Count > 0)
  29. {
  30. return true;
  31. }
  32.  
  33. var fallbackItem = item.GetFallbackItem();
  34. return fallbackItem != null && fallbackItem.Versions.Count > 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement