public IEnumerable <TimeSlotAvailability> CalculateAvailability(List <Schedule> mySchedules, DateTime startDate, DateTime endDate, byte startHour, byte endHour, AvailabilityTimeUnit grain) { var workingTimeSlots = new ConcurrentBag <TimeSlot>(); var startDateTime = startDate.Date.AddHours(startHour); var endDateTime = endDate.Date; Parallel.ForEach(mySchedules, s => { var theseTimeSlots = ExpandSchedule(s, startDateTime, endDateTime); foreach (var ts in theseTimeSlots) { workingTimeSlots.Add(ts); } }); var outAvailability = new List <TimeSlotAvailability>(); var timeStep = TimeSpan.FromMinutes((int)grain); if (grain == AvailabilityTimeUnit.Day) { timeStep = TimeSpan.FromHours(endHour - startHour); } for (var dateCounter = 0; dateCounter <= endDate.Date.Subtract(startDate.Date).Days; dateCounter++) { for (var timeCounter = TimeSpan.FromHours(startHour); timeCounter < TimeSpan.FromHours(endHour); timeCounter = timeCounter.Add(timeStep)) { var thisAvailability = new TimeSlotAvailability() { StartDateTime = startDate.Date.AddDays(dateCounter).Add(timeCounter), EndDateTime = startDate.Date.AddDays(dateCounter).Add(timeCounter).Add(timeStep), Count = 0 }; // CALCULATE thisAvailability.Count = workingTimeSlots .Count(t => t.Overlaps(thisAvailability) && t.Status == ScheduleStatus.Available); outAvailability.Add(thisAvailability); } } return(outAvailability); }
public TimeSlotAvailability GetTimeSlotInfoWithServProvIdParams([FromBody] TimeSlotParams time_slot_param) { Authentication_class var_auth = new Authentication_class(); AuthenticationHeader ah = var_auth.getAuthHeader(time_slot_param.username_ad, time_slot_param.password_ad); AsmRepository.SetServiceLocationUrl(var_auth.var_service_location_url); IWorkforceService woService = AsmRepository.AllServices.GetWorkforceService(ah); ICustomersService customerService = AsmRepository.GetServiceProxyCachedOrDefault <ICustomersService>(ah); DateTime dt = DateTime.ParseExact(time_slot_param.Date, "yyyy-MM-dd", CultureInfo.InvariantCulture); Customer cust = new Customer(); cust = customerService.GetCustomer(time_slot_param.customer_id); var sp = woService.FindSPServiceWithGeoInfo(new FindSPServiceCriteria() { AddressId = time_slot_param.serv_addr_id, ServiceTypeId = time_slot_param.serv_type_id, ServiceProviderId = time_slot_param.serv_prov_id, Active = true, PageSize = 100 }, 1); TimeSlotAvailability var_timeslotAvailability = new TimeSlotAvailability(); var var_timeslotAvailabilityItem = new List <TimeSlotAvailabilityItem>(); foreach (SPServiceWithGeoInfo serviceprovider in sp.Items) { var sps = woService.GetServiceProviderServiceByServiceTypeGeoDefGroupIdandProviderId(serviceprovider.ServiceTypeId.Value, serviceprovider.GeoDefinitionGroupId.Value, serviceprovider.ServiceProviderId.Value); TimeSlotDescription[] timeslot = woService.GetTimeSlotsByServiceProviderServiceId(sps.Id.Value, dt); // print the timeslot for this service var_timeslotAvailabilityItem.Add(new TimeSlotAvailabilityItem() { the_SPServiceWithGeoInfo = serviceprovider, the_timeslot = timeslot }); } var_timeslotAvailability.TimeItemsData = var_timeslotAvailabilityItem; return(var_timeslotAvailability); }