public double CheckCustomerLocations(string customerId, int bookingId) { var booking = _bookingRepository.GetAll() .Where(b => b.Id == bookingId) .Include(b => b.Barber) .First(); var bookedTime = booking.BookedTime; var currentTime = DateTimeUtil.GetTimeNow(); if (currentTime < bookedTime.AddMinutes(booking.DurationMinute * BookingConstants.BarberLatencyPercentage)) { return(0); } var barber = booking.Barber; var locations = GetCustomerLocations(customerId, bookingId) .Where(l => bookedTime <= l.Time && l.Time <= currentTime) .ToList(); double customerInPlaceCount = 0; foreach (var location in locations) { var distance = LocationUtil.CalculateDistance(location.GpsLong, location.GpsLat, barber.Longitude.GetValueOrDefault(), barber.Latitude.GetValueOrDefault()); if (distance <= LocationUtil.AcceptableDistance) { customerInPlaceCount += 1; } } return(customerInPlaceCount / locations.Count); }
public bool CheckinSlot(int bookingId, double longitude, double latitude, out Dictionary <DateTimeOffset, List <TimePoint> > suggestTimes) { suggestTimes = null; Bookings booking = _bookingRepository.GetBooking(bookingId, true); //Check location Barbers barber = booking.Barber; double distance = LocationUtil.CalculateDistance(longitude, latitude, barber.Longitude.GetValueOrDefault(), barber.Latitude.GetValueOrDefault()); if (distance > LocationUtil.AcceptableDistance) { return(false); } //Check in-time if (booking.State == BookingConstants.Suspended) { var bookedServices = booking.BookingServices.Select(bs => bs.Service).ToList(); suggestTimes = GetAvailableSlots(booking.BarberId, new List <DateTimeOffset> { DateTimeUtil.GetToday() }, bookedServices); return(false); } //Update state if (booking.State == BookingConstants.Booked) { booking.State = BookingConstants.CheckedIn; _bookingRepository.UpdateBooking(booking); return(true); } return(false); }