我有一個約會服務,它回傳一個約會串列,我想從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"));
但是當串列顯示時,它會回傳所有約會而不過濾它們,那么問題是什么,我該如何解決?
uj5u.com熱心網友回復:
這是錯誤的
else if (appointments == null && str == "up")
它應該是
else if (appointments != null && str == "up")
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/470478.html
標籤:C# xml xamarin xamarin.forms xamarin.android