Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4266198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:43:39+00:00 2026-05-21T06:43:39+00:00

public static List<PreviewSchedule> BuildPreviewSchedule(Chatham.Business.Objects.Transaction transaction) { List<PreviewSchedule> items = new List<PreviewSchedule>(); List<ScheduleItem> scheduleItems =

  • 0
public static List<PreviewSchedule> BuildPreviewSchedule(Chatham.Business.Objects.Transaction transaction)
        {
            List<PreviewSchedule> items = new List<PreviewSchedule>();
            List<ScheduleItem> scheduleItems = new List<ScheduleItem>(transaction.ScheduleCollection.FindAll(row => row.IsDeleted == false));

            bool allFromDateFilledIn = !scheduleItems.Exists(item => !item.FromDate.HasValue);
            bool allFloatingFromDateFilledIn = !scheduleItems.Exists(item => !item.FloatingFromDate.HasValue);

            scheduleItems.Sort((a, b) => a.FromDate.GetValueOrDefault().CompareTo(b.FromDate.GetValueOrDefault()));

            scheduleItems.Sort((a, b) => SortIt(a, b, allFromDateFilledIn, allFloatingFromDateFilledIn));

            for (int i = 0; i < scheduleItems.Count; i++)
            {
                items.Add(new PreviewSchedule
                {
                    Drop = i == 0 ? "$0.00" :
                    ((scheduleItems[i - 1].PrincipalNotionalAmount - scheduleItems[i].PrincipalNotionalAmount)).Value.ToString(Format.CurrencyCentsIncludedFormatStringDollarSign),
                    EndDate = GetDateOrNull(scheduleItems[i].ToDate),
                    StartDate = GetDateOrNull(scheduleItems[i].FromDate),
                    Notional = scheduleItems[i].PrincipalNotionalAmount.Value.ToString(Format.CurrencyCentsIncludedFormatStringDollarSign),
                    FloatingEndDate = GetDateOrNull(scheduleItems[i].FloatingToDate),
                    FloatingStartDate = GetDateOrNull(scheduleItems[i].FloatingFromDate)
                });
            }
            return items;
        }

Here is the method that we call to return our schedule to the front end in our mvc app. Now, this list has been mixing up the last two rows on a specific model the same way each time. Look at the pic:
enter image description here

Last two rows of the table, you can obviously see the last two rows are switched around, because the dates don’t follow each other. This method is spitting back those mixed up dates, and I’m thinking it’s a problem with the sorting. Can any of you guys see where the sorting would cause this?

Thanks ahead of time.

Edit:

SortIt() code:

private static int SortIt(
           Chatham.Business.Objects.ScheduleItem a,
           Chatham.Business.Objects.ScheduleItem b,
            bool allFromDateFilledIn,
           bool allFloatingFromDateFilledIn)
        {
            return SortIt(a.FromDate, a.FloatingFromDate, b.FromDate, b.FloatingFromDate, allFromDateFilledIn, allFloatingFromDateFilledIn);
        }

        private static int SortIt(DateTime? aFrom, 
            DateTime? aFloatingFrom, 
            DateTime? bFrom, 
            DateTime? bFloatingFrom, 
            bool allFromDateFilledIn,
            bool allFloatingFromDateFilledIn)
        {
            DateTime? a = null;
            DateTime? b = null;
            if (allFromDateFilledIn == false && allFloatingFromDateFilledIn == false)
            {
                a = aFrom ?? aFloatingFrom;
                b = bFrom ?? bFloatingFrom;
            }
            else
            {
                a = allFromDateFilledIn ? aFrom : aFloatingFrom;
                b = allFromDateFilledIn ? bFrom : bFloatingFrom;
            }

            if (a.HasValue && b.HasValue)
                return a.Value.CompareTo(b.Value);

            return 0;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:43:40+00:00Added an answer on May 21, 2026 at 6:43 am

    I notice the second-to-last row is the only one that has all four dates filled in. I also notice that 01-Oct-2013 is before 01-Nov-2013. I strongly suspect those are the dates being compared together. I can’t completely diagnose or correct the issue without knowing what the SortIt method looks like, though. Regardless, that’s probably the source of your problem, so I’d focus your efforts there.

    Consider what should happen when all four dates are filled in, and figure out how to handle that case.

    Edit:

    Now that you’ve added the SortIt code, take a look at your allFromDateFilledIn and allFloatingFromDateFilledIn flags. Both of these are always going to be false with your example data, because both the From and FloatingFrom columns contain at least one null cell somewhere. Therefore, your SortIt method is always going to evaluate this:

    a = aFrom ?? aFloatingFrom;
    b = bFrom ?? bFloatingFrom;
    

    …which means comparing values from different columns together. It also means that when both From and FloatingFrom exist, From always wins as the comparison value.

    Edit 2:

    You could try replacing the above with an inner if/else like this:

    if (aFrom != null && bFrom != null)
    {
        a = aFrom;
        b = bFrom;
    }
    else if (aFloatingFrom != null && bFloatingFrom != null)
    {
        a = aFloatingFrom;
        b = bFloatingFrom;
    }
    else
    {
        a = aFrom ?? aFloatingFrom;
        b = bFrom ?? bFloatingFrom;
    }
    

    I feel like maybe that logic could be reduced/prettified, but it seems easiest to understand this way. Note that From still has higher priority than FloatingFrom.

    You might want to consider what your boolean flags are doing, as well. They’ll only come into play when one or the other column is completely full, in which case they’ll lock-in that column as the comparison column. That may be what you want, or it may be unnecessary. You’ve already established that From takes precedence over FloatingFrom, so without a reason to override that rule, I’d just follow it for the sake of consistency. Just a thought.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Generic List as below public static readonly List<Customer> Customers = new
public static UserFriendListContainer getFriendList(SoapObject wizardobject)//TESTED { UserFriendListContainer container= new UserFriendListContainer(); List<UserFriendListModel> list= new ArrayList();
public static List<Long> abc = new ArrayList<Long>(){{ //Asks for SerialVersionUID abc.add(5L); abc.add(7L); }}; public
public class Utils { public static List<Message> getMessages() { //File file = new File(file:///android_asset/helloworld.txt);
I have this code : public static List<string> MyTable = new List<string>(); dsView =
I have this method public static List<SummaryItinerary> ReturnBookingsByUserGuid(Guid userGuid) { var entities = new
I have a static list: public static List<IMachines>mList =new List<IMachines>(); The list intakes two
public static List<double[]> pc = new LinkedList(); public void fillTable1() { int index =
class A { public static List<String> a = new List<string>(); public static List<String> test()
import java.util.*; public class Test { static List<Integer> list = new LinkedList<Integer>(); public static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.