コード例 #1
0
        public async Task<List<TracksDto>> MakeSearch(string searchText, string criteria)
        {
            var trackDtos = new List<TracksDto>();
            var tracks = new List<Track>();
            var findInVk = new List<TrackData.Audio>();
            using (var unitOfWork = _unitOfWorkFactory.NewUnitOfWork())
            {
                //var socialNetworkData = GetSocialNetworkData(unitOfWork, "Vkontakte");
                UserSocialNetwork socialNetworkData;
                _socialNetworkApi = SocialNetworkApiFactory.GetSocialNetworkApi("Vkontakte");
                var trackRepository = unitOfWork.GetRepository<Track>();

                switch (criteria)
                {
                    case "genre":
                        tracks = trackRepository.Get(track => track.Genre.ToLower().Contains(searchText)).ToList();
                        break;
                    case "artist":
                        tracks =
                            trackRepository.Get(track => track.Album.Artist.Name.ToLower().Contains(searchText))
                                .ToList();
                        break;
                    case "track":
                        tracks = trackRepository.Get(track => track.Name.ToLower().Contains(searchText)).ToList();
                        break;
                    case "vkontakte":
                        if (AzimuthIdentity.Current.UserCredential.SocialNetworkName != "Vkontakte")
                        {
                            var id = unitOfWork.UserRepository.Get(user =>
                                user.ScreenName == "id268940215" && user.Name.FirstName == "Azimuth" &&
                                user.Name.LastName == "Azimuth").FirstOrDefault().Id;

                            var admin =
                                unitOfWork.UserRepository.GetFullUserData(id);
                            socialNetworkData =
                                admin.SocialNetworks.FirstOrDefault(sn => sn.SocialNetwork.Name == "Vkontakte");
                        }
                        else
                        {
                            socialNetworkData = GetSocialNetworkData(unitOfWork, "Vkontakte");
                        }
                        findInVk =
                            await _socialNetworkApi.SearchTracks(searchText, socialNetworkData.AccessToken, 0, 0, 20);
                        if (findInVk.Count > 0)
                        {
                            findInVk.ForEach(item =>
                            {
                                var dto = new TracksDto();
                                Mapper.Map(item, dto);
                                if (!trackDtos.Any(track => (track.Artist == dto.Artist) && (track.Name == dto.Name)))
                                {
                                    trackDtos.Add(dto);
                                }
                            });
                        }
                        break;
                    case "myvktracks":
                        socialNetworkData = GetSocialNetworkData(unitOfWork, "Vkontakte");
                        findInVk =
                            await
                                _socialNetworkApi.GetTracks(socialNetworkData.ThirdPartId, socialNetworkData.AccessToken);
                        findInVk =
                            findInVk.Where(
                                s =>
                                    s.Title.ToLower().Contains(searchText) ||
                                    s.GenreId.ToString().ToLower().Contains(searchText) ||
                                    s.Artist.ToLower().Contains(searchText)).ToList();

                        if (findInVk.Count > 0)
                        {
                            findInVk.ForEach(item =>
                            {
                                var dto = new TracksDto();
                                Mapper.Map(item, dto);
                                if (!trackDtos.Any(track => (track.Artist == dto.Artist) && (track.Name == dto.Name)))
                                {
                                    trackDtos.Add(dto);
                                }
                            });
                        }
                        break;
                }

                if (tracks.Count > 0)
                {
                    tracks.ForEach(item =>
                    {
                        var dto = new TracksDto();
                        Mapper.Map(item, dto);
                        if (!trackDtos.Any(track => (track.Artist == dto.Artist) && (track.Name == dto.Name)))
                        {
                            trackDtos.Add(dto);
                        }
                    });
                }

                unitOfWork.Commit();
            }

            return trackDtos;
        }
コード例 #2
0
 public async Task<List<TracksDto>> VkontakteSearch(string searchText, int offset)
 {
     var trackDtos = new List<TracksDto>();
     var findInVk = new List<TrackData.Audio>();
     _socialNetworkApi = SocialNetworkApiFactory.GetSocialNetworkApi("Vkontakte");
     UserSocialNetwork socialNetworkData;
     using (var unitOfWork = _unitOfWorkFactory.NewUnitOfWork())
     {
         socialNetworkData = GetSocialNetworkData(unitOfWork, "Vkontakte");
         unitOfWork.Commit();
     }
     findInVk = await _socialNetworkApi.SearchTracks(searchText, socialNetworkData.AccessToken, 0, offset, 20);
     if (findInVk.Count > 0)
     {
         findInVk.ForEach(item =>
         {
             var dto = new TracksDto();
             Mapper.Map(item, dto);
             if (!trackDtos.Any(track => (track.Artist == dto.Artist) && (track.Name == dto.Name)))
             {
                 trackDtos.Add(dto);
             }
         });
     }
     return trackDtos;
 }