/ThinkEmailFomatter/Utilities/Extensions/LinqComparer.cs
C# | 52 lines | 49 code | 3 blank | 0 comment | 18 complexity | 378d9043658da6cdb496051634f02a06 MD5 | raw file
Possible License(s): BSD-3-Clause
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.IO;
- using System.Xml;
- using System.Xml.Linq;
- using ThinkEmailFormatter.Models;
- using System.Web.Mvc;
- using Microsoft.Practices.EnterpriseLibrary.Logging;
- using System.Diagnostics;
- using System.Text;
- namespace ThinkEmailFormatter.Models.Extensions
- {
- public class FilterComparer : IComparer<Filter>
- {
- public int Compare(Filter x, Filter y)
- {
- int xOrderCode = x.OrderCode == null ? 0 : x.OrderCode.Id;
- int xSourceCode = x.SourceCode == null ? 0 : x.SourceCode.Id;
- int xSubDef = x.SubscriptionDefinition == null ? 0 : x.SubscriptionDefinition.Id;
- int yOrderCode = y.OrderCode == null ? 0 : y.OrderCode.Id;
- int ySourceCode = y.SourceCode == null ? 0 : y.SourceCode.Id;
- int ySubDef = y.SubscriptionDefinition == null ? 0 : y.SubscriptionDefinition.Id;
- if (xSourceCode > ySourceCode)
- return 1;
- else if (xSourceCode == ySourceCode)
- {
- if (xSubDef > ySubDef)
- return 1;
- else if (xSubDef == ySubDef)
- {
- if (xOrderCode > yOrderCode)
- return 1;
- else if (xOrderCode == yOrderCode)
- {
- return 0;
- }
- else
- return -1;
- }
- else
- return -1;
- }
- else
- return -1;
- }
- }
- }