Beispiel #1
0
        public override bool Equals(object obj)
        {
            if (obj.GetType() != this.GetType())
            {
                return(false);
            }

            Barber other = (Barber)obj;

            return(string.Equals(other.DisplayName, DisplayName, StringComparison.OrdinalIgnoreCase));
        }
Beispiel #2
0
        public async Task <AppointmentRequest> NextAvailableBarberAsync(AppointmentRequest appointmentRequest)
        {
            var barbers = await LoadBarbersAsync(false);

            Barber             nextAvailable = null;
            AppointmentRequest nextRequest   = new AppointmentRequest(this);

            nextRequest.CopyFrom(appointmentRequest);

            int attempts = 0;

            while (nextAvailable == null && attempts < ShopHours.SuggestionAttempts)
            {
                foreach (var barber in barbers)
                {
                    BarberAvailabilityResponse availabilityResponse = await barber.IsAvailableAsync(nextRequest);

                    if (availabilityResponse.IsAvailable)
                    {
                        nextAvailable = barber;
                        break;
                    }
                }

                if (nextAvailable == null)
                {
                    DateTime nextDateTimeCheck = nextRequest.StartDateTime.Add(ShopHours.SuggestionAttemptIncrement);
                    if (!await IsOpenAsync(nextDateTimeCheck))
                    {
                        nextDateTimeCheck = nextDateTimeCheck.AddDays(1);
                        await Hours.LoadAsync(this, nextDateTimeCheck);

                        nextDateTimeCheck = Hours.OpeningDateTime();
                    }
                    nextRequest = new AppointmentRequest(this);
                    nextRequest.CopyFrom(appointmentRequest);
                    attempts++;
                }
            }

            if (nextAvailable == null)
            {
                // if we can't find a barber this is not a valid request.
                nextRequest = null;
            }
            else
            {
                nextRequest.RequestedBarber = nextAvailable;
            }

            return(nextRequest);
        }
Beispiel #3
0
        public bool IsConflicting(Appointment appointment)
        {
            if (!Barber.Equals(appointment.Barber))
            {
                return(false);
            }

            if (StartDateTime == appointment.StartDateTime)
            {
                return(true);
            }
            else if (StartDateTime < appointment.StartDateTime)
            {
                if (EndDateTime <= appointment.StartDateTime)
                {
                    return(false);
                }
                else if (StartDateTime > appointment.EndDateTime)
                {
                    return(true);
                }
                else if (EndDateTime < appointment.EndDateTime ||
                         EndDateTime >= appointment.EndDateTime)
                {
                    return(true);
                }
            }
            else // StartDateTime > appointment.StartDateTime
            {
                if (StartDateTime >= appointment.EndDateTime)
                {
                    return(false); // adjacent
                }
                return(true);
            }

            return(false);
        }
Beispiel #4
0
 public override int GetHashCode()
 {
     return(Shop.GetHashCode() ^ Barber.GetHashCode() ^ StartDateTime.GetHashCode() ^ EndDateTime.GetHashCode());
 }