public static int ComparebyDistance(MobileServiceOrgUnitDto dto1, MobileServiceOrgUnitDto dto2) { //If both have invalid distance then compare by name, if either of one is invalid move it to the last if (dto1.Distance == 0 && dto2.Distance == 0) return ComparebyName(dto1, dto2); if (dto1.Distance == 0 && dto2.Distance > 0) return 1; if (dto1.Distance > 0 && dto2.Distance == 0) return -1; //If same distance then sort by name if (dto1.Distance > 0 && dto2.Distance > 0 && dto1.Distance == dto2.Distance) return ComparebyName(dto1, dto2); return dto1.Distance.CompareTo(dto2.Distance); }
public static int ComparebyName(MobileServiceOrgUnitDto dto1, MobileServiceOrgUnitDto dto2) { return String.Compare(dto1.ServiceName, dto2.ServiceName, StringComparison.OrdinalIgnoreCase); }