0

我正在尝试进行预约系统。唯一的问题是,如果接受了另一个约会,我不想让客户创建约会。

我想在预约之间留出 1 小时,如果预约 A 是在 12:00,你不能在 12:00 到 13:00 之间预约

这是我的代码:

List<Appointment> acceptedAppointments = new Service1Client().getAllAcceptedAppointments();

获得所有接受的约会。

foreach (Appointment item in acceptedAppointments)
            {
                if (item.Appointment_DateTime.Date == myDate.Date)
                {
                    if (myDate.AddHours(1) > item.Appointment_DateTime)
                    {

                    }
                }
            }

如果有人可以提供帮助,我不知道我需要在这里做什么,非常感谢!

4

1 回答 1

2
bool isValidAppointment = true;

// Go through all accepted appointments
foreach (Appointment item in acceptedAppointments)
{
    // Check if the difference between the appointments is less than 60 minutes
    if (item.Appointment_DateTime.Substract(myDate).Duration.TotalMinutes < 60)
    {
        // If so, set bool to indicate invalid appointment and stop validation
        isValidApopintment = false;
        break;
    }
}

if (isValidAppointment)
{
    // Handle valid appointment
}
else
{
    // Handle invalid appointment
}

这可以缩短为:

bool isValidApointment = acceptedAppointments.Any(x => x.Substract(myDate).Duration.TotalMinutes < 60);
于 2013-05-11T15:28:59.090 回答