//Hämtar totalt antal klick för bransch relationerna private async Task <int> GetTotalClicksInBranchRelations(List <BookingSystem> onlyOneOfEachBranch, BookingSystem selectedBookingSystem, Service selectedService) { List <BookingSystemOfInterest> bookingSystemsOfInterest = GetBookingsWithDistance(onlyOneOfEachBranch, selectedBookingSystem).Result; BranchRepository branchRepository = new BranchRepository(ApplicationDbContext); int totClick = 0; List <Service> servicesWithRelationToSelectedService = new List <Service>(); foreach (var bookingSystemOfInterest in bookingSystemsOfInterest) { foreach (var service in bookingSystemOfInterest.bookingSystem.Services) { if (selectedService.Branch.BranchRelations.Any(x => x.branchBId2 == service.Branch.BranchId.ToString())) { servicesWithRelationToSelectedService.Add(service); } } } foreach (var relation in selectedService.Branch.BranchRelations) { if (servicesWithRelationToSelectedService.Any(x => x.Branch.BranchId.ToString() == relation.branchBId2)) { totClick += relation.CountClick; } } return(await Task.FromResult(totClick)); }
//Hämtar antalet poäng som den valda tjänsten har fått private async Task <List <ClickOfService> > GetClickOfServices(List <DistanceScoreAndBookingSystem> distanceScoreAndBookingSystem, Service selectedService, int totClick) { BranchRepository branchRepository = new BranchRepository(ApplicationDbContext); List <ClickOfService> clickOfService = new List <ClickOfService>(); foreach (var item in distanceScoreAndBookingSystem) { //Distanspoäng + baspoäng double counter = item.distanceScore + 5; foreach (var service in item.bookingSystemOfInterest.bookingSystem.Services) { double score = 1; if (selectedService.Branch.BranchRelations.Any(y => y.branchBId2 == service.Branch.BranchId.ToString())) { //Skapar en branschrelation med den valda tjänsten BranchRelation branchRelation = selectedService.Branch.BranchRelations.Single(x => x.branchBId2 == service.Branch.BranchId.ToString()); //Räknar antalet bokningar(klick för att boka) int click = branchRelation.CountClick; score += (double)click / totClick; } ClickOfService aObject = new ClickOfService(); aObject.service = service; aObject.score = score * counter; clickOfService.Add(aObject); } } return(await Task.FromResult(clickOfService)); }