public async Task <AppointmentAvailabilityResponse> IsAvailableAsync(AppointmentRequest appointmentRequest) { AppointmentAvailabilityResponse response = new AppointmentAvailabilityResponse(); var dateTimeToCheck = appointmentRequest.StartDateTime.Add(minimumTimeBeforeClose); DateTime nowDateTime = DateTime.UtcNow.AddHours(ShopHours.UTC_to_PST_Hours); // convert to PST. await Hours.LoadAsync(this, nowDateTime.Date); // today's hours // check holidays // is it in the past? if (dateTimeToCheck < nowDateTime) { response.ValidationResults.Add(new ValidationResult() { Message = "Appointments can't be scheduled before right now. " }); return(response); } // is the store open? await Hours.LoadAsync(this, dateTimeToCheck); if (!Hours.Exists) { response.ValidationResults.Add(new ValidationResult() { Message = "The shop isn't open that day. " }); return(response); } // is it between hours bool isWithinHours = Hours.IsWithinHours(appointmentRequest.StartDateTime); // does it meet the minimum window? bool meetsMinimum = Hours.IsWithinHours(dateTimeToCheck); if (isWithinHours && meetsMinimum) { response.IsAvailable = true; } else if (!isWithinHours) { response.ValidationResults.Add(new ValidationResult() { Message = $"The appointment isn't between store hours of {Hours.FormattedDayHours()}. " }); } else if (!meetsMinimum) { response.ValidationResults.Add(new ValidationResult() { Message = $"The appointment needs to be at least {minimumTimeBeforeClose} minutes before closing. Hours are {Hours.FormattedDayHours()}. " }); } return(response); }
public string FormattedWeekHours() { DateTime opening = OpeningDateTime(); StringBuilder stringBuilder = new StringBuilder(); int beginningEnumCounter = (int)opening.DayOfWeek; int daysToSubtract = 0; while (beginningEnumCounter > 0) { daysToSubtract++; beginningEnumCounter--; } for (int days = daysToSubtract; days >= 0; days--) { ShopHours day = new ShopHours(this); DateTime dateTimeCheck = opening.AddDays(-1 * days); stringBuilder.AppendLine(day.FormattedDayHours()); } return(stringBuilder.ToString()); }