日期时间比较 Xamarin.Forms

DateTime comparing in Xamarin.Forms

我有一个约会服务,其中 return 一个约会列表,我想 return 来自 firebase 数据库的即将到来的约会,所以我这样做了 :

public static async Task<IEnumerable<Appoitment>> GetUserAppointmentsByDate(DateTime? dateTime , string str)
{
    var Patients = await PatientService.GetUserPatients();

    if (Patients == null)
        return new List<Appoitment>();
    else
    {
        List<Appoitment> appointments = new List<Appoitment>();

        foreach (var patient in Patients)
        {
            if (patient.Appointments != null)
                appointments.AddRange(patient.Appointments.Values);
        }

        if (appointments == null && str == "all")
            return new List<Appoitment>();
        else if (appointments == null && str == "up")
            return (appointments.Where(o => o.AppointmentDate.Date.Date > DateTime.Now.Date));
        else if (dateTime.HasValue)
            return (appointments.Where(o => o.AppointmentDate.Date.Date == dateTime.Value.Date));
        else
            return appointments;
    }
}

然后我这样称呼它:

Appoitments = new ObservableCollection<Appoitment>(await AppintmentService.GetUserAppointmentsByDate(null,"up"));

但是当显示列表时,它是 return 所有约会而没有过滤它们,所以问题是什么,我该如何解决?

这是错误的

else if (appointments == null && str == "up")

应该是

else if (appointments != null && str == "up")