Esempio n. 1
0
        public SearchClubsOutput GetClubs()
        {
            var clubs  = _clubRepository.GetAllList();
            var output = new SearchClubsOutput();

            foreach (var club in clubs)
            {
                output.Clubs.Add(new ClubSearchDto
                {
                    Name = club.Name
                });
            }
            return(output);
        }
Esempio n. 2
0
        /// <summary>
        /// Ermittelt alle Clubs die in einem angegebenen Bereich liegen inkl.
        /// der Besucher und Freunde in den Clubs
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <SearchClubsOutput> SearchClubs(SearchClubsInput input)
        {
            DateTime          actTime        = input.ActualTime.HasValue ? input.ActualTime.Value : DateTime.Now;
            GeoPoint          actualPoint    = new GeoPoint(input.Latitude, input.Longitude);
            DbGeography       actualGeoPoint = DbGeography.FromText(actualPoint.ToString());
            SearchClubsOutput output         = new SearchClubsOutput();

            var friends = _memberRepository.GetAll()
                          .Include(x => x.Friends)
                          .Where(x => x.UserName.ToUpper() == input.UserName.ToUpper()).First()
                          .Friends.ToList();

            double distanceM = input.DistanceKm * 1000;

            var clubs = _clubRepository.GetAll()
                        .Include(x => x.OpenTimes)
                        .Include(x => x.Categories);

            if (input.Latitude > 0)
            {
                clubs = clubs.Where(x => x.Location.Distance(actualGeoPoint) < distanceM);
            }

            var clubsDto = new List <ClubSearchDto>();

            foreach (var club in clubs.ToList())
            {
                double distanceToClub = Geo.Distance(actualPoint, new GeoPoint(club.Latitude, club.Longitude));
                if (input.Latitude == 0 || distanceToClub <= input.DistanceKm)
                {
                    var visits = await _clubVisitRepository.GetAll().Where(x => x.ClubId == club.Id &&
                                                                           !x.HasLeft && actTime <= x.LeavingDate).ToListAsync();

                    int numberOfVisits = visits.Count();

                    int numberOfFriends = visits.Select(x => x.MemberId).Intersect(friends.Select(x => x.Id)).Count();

                    var imageModification = await _clubImageRepository.GetAll()
                                            .Where(x => x.Id == club.Id)
                                            .Select(x => x.LastModificationTime)
                                            .FirstOrDefaultAsync();

                    ClubSearchDto clubDto = new ClubSearchDto
                    {
                        Id                        = club.Id,
                        Name                      = club.Name,
                        IsOpen                    = club.IsOpen(actTime),
                        Distance                  = Geo.Distance(actualPoint, new GeoPoint(club.Latitude, club.Longitude)),
                        Longitude                 = club.Longitude,
                        Latitude                  = club.Latitude,
                        Categories                = string.Join(", ", club.Categories.Select(x => x.Name)),
                        FriendsInside             = numberOfFriends,
                        PeopleInside              = numberOfVisits,
                        LastImageModificationTime = imageModification
                    };

                    clubsDto.Add(clubDto);
                }
            }
            output.Clubs = clubsDto.OrderBy(x => x.Distance).ToList();
            return(output);
        }