PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/ThinkEmailFomatter/Utilities/Extensions/LinqComparer.cs

https://bitbucket.org/nicdao/frg-think-emailformatter
C# | 52 lines | 49 code | 3 blank | 0 comment | 18 complexity | 378d9043658da6cdb496051634f02a06 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.IO;
  6. using System.Xml;
  7. using System.Xml.Linq;
  8. using ThinkEmailFormatter.Models;
  9. using System.Web.Mvc;
  10. using Microsoft.Practices.EnterpriseLibrary.Logging;
  11. using System.Diagnostics;
  12. using System.Text;
  13. namespace ThinkEmailFormatter.Models.Extensions
  14. {
  15. public class FilterComparer : IComparer<Filter>
  16. {
  17. public int Compare(Filter x, Filter y)
  18. {
  19. int xOrderCode = x.OrderCode == null ? 0 : x.OrderCode.Id;
  20. int xSourceCode = x.SourceCode == null ? 0 : x.SourceCode.Id;
  21. int xSubDef = x.SubscriptionDefinition == null ? 0 : x.SubscriptionDefinition.Id;
  22. int yOrderCode = y.OrderCode == null ? 0 : y.OrderCode.Id;
  23. int ySourceCode = y.SourceCode == null ? 0 : y.SourceCode.Id;
  24. int ySubDef = y.SubscriptionDefinition == null ? 0 : y.SubscriptionDefinition.Id;
  25. if (xSourceCode > ySourceCode)
  26. return 1;
  27. else if (xSourceCode == ySourceCode)
  28. {
  29. if (xSubDef > ySubDef)
  30. return 1;
  31. else if (xSubDef == ySubDef)
  32. {
  33. if (xOrderCode > yOrderCode)
  34. return 1;
  35. else if (xOrderCode == yOrderCode)
  36. {
  37. return 0;
  38. }
  39. else
  40. return -1;
  41. }
  42. else
  43. return -1;
  44. }
  45. else
  46. return -1;
  47. }
  48. }
  49. }