public SearchResult(VideoSearchType videoSearchType, string searchFor) { _searchfor = searchFor; _videoSearchType = videoSearchType; this.AddTrigger( ControllerRepository.GetInfo <IDbController, Task>(x => x.SaveCategory(null)), ControllerRepository.GetInfo <IDbController, Task>(x => x.SaveVideo(null))); InitializeComponent(); }
public List <RatingModelView> GetItemRating(VideoSearchType type, List <long> ids) { using (var db = new DbRepository()) { var result = new List <RatingModelView>(); foreach (var id in ids) { result.Add(new RatingModelView() { Entity_Id = id, VideoSearchType = type, Rating_Down = (type == VideoSearchType.Videos ? db.Get <Rating>().Where(x => x.Ratingtype == Ratingtype.Down && x.VideoData_Id == id).ExecuteCount() : db.Get <Rating>().Where(x => x.Ratingtype == Ratingtype.Down && x.Category_Id == id).ExecuteCount()).ConvertValue <long?>().RoundAndFormat(), Rating_Up = (type == VideoSearchType.Videos ? db.Get <Rating>().Where(x => x.Ratingtype == Ratingtype.Up && x.VideoData_Id == id).ExecuteCount() : db.Get <Rating>().Where(x => x.Ratingtype == Ratingtype.Up && x.Category_Id == id).ExecuteCount()).ConvertValue <long?>().RoundAndFormat() }); } return(result); } }
public void Vote(VideoSearchType type, Ratingtype ratingtype, long id, long userid) { using (var db = new DbRepository()) { if (type == VideoSearchType.Videos) { var video = db.Get <VideoData>().Where(x => x.EntityId == id).ExecuteFirstOrDefault(); db.Get <Rating>().Where(x => x.VideoData_Id == id && x.User_Id == userid).Remove(); var rating = new Rating(); if (video.Rating == null) { video.Rating = new List <Rating>(); } video.Rating.Add(new Rating() { Ratingtype = ratingtype, User_Id = userid, }); db.Save(video).SaveChanges(); } else { var video = db.Get <VideoCategory>().Where(x => x.EntityId == id).ExecuteFirstOrDefault(); db.Get <Rating>().Where(x => x.Category_Id == id && x.User_Id == userid).Remove(); var rating = new Rating(); if (video.Rating == null) { video.Rating = new List <Rating>(); } video.Rating.Add(new Rating() { Ratingtype = ratingtype, User_Id = userid, }); db.Save(video).SaveChanges(); } } }
public YoutubeVideoCollection Search(string searchString, int pageSize = 50, string relatedTo = null, VideoSearchType videoSearchType = VideoSearchType.Videos) { // my code }
/// <summary> /// Search Youtube /// </summary> /// <param name="searchText"></param> /// <returns></returns> public async Task <IEnumerable <VideoWrapper> > SearchAsync(string searchText, string relatedTo = null, VideoSearchType videoSearchType = VideoSearchType.Videos, int pageNumber = 1, int pageSize = 20) { if (!string.IsNullOrEmpty(relatedTo)) { searchText = $"(\"{searchText}\" | {string.Join("\"{0}\"|", relatedTo.Split(','))})"; } SearchFilterType searchFilterType = SearchFilterType.Default; switch (videoSearchType) { case VideoSearchType.Videos: searchFilterType = SearchFilterType.Video; break; case VideoSearchType.Album: case VideoSearchType.PlayList: case VideoSearchType.Recommendation: searchFilterType = SearchFilterType.Playlist; break; case VideoSearchType.Mix: case VideoSearchType.All: searchFilterType = SearchFilterType.Default; break; case VideoSearchType.Channel: searchFilterType = SearchFilterType.Channel; break; case VideoSearchType.Rating: searchFilterType = SearchFilterType.Rating; break; } var data = await dataContext.SearchVideosByFilterAsync(searchText, pageNumber, pageSize, searchFilterType); return((string.IsNullOrEmpty(searchText) ? data.OrderByDescending(x => x.Statistics.ViewCount) : data.OrderBy(x => x.Title.Contains(searchText)).ThenByDescending(x => x.Statistics.ViewCount)).Select(x => Create(x))); }
public async Task <YVideoCollection> SearchAsync(long userId, string searchString, int pageSize, int pageNumber, string relatedTo = null, VideoSearchType videoSearchType = VideoSearchType.Videos) { var result = new YVideoCollection(); using (var db = new DbRepository()) { var m = new YManager(); var videoResult = $"{searchString}, -\"Playlist\""; var albumResult = $"{searchString}, +\"Albums\", \"Playlist\""; var playListResult = $"{searchString}, +\"Playlist\""; if (videoSearchType == VideoSearchType.Videos || videoSearchType == VideoSearchType.All || videoSearchType == VideoSearchType.Mix) { result.Videos.AddRange(await m.SearchAsync(videoResult, relatedTo, videoSearchType != VideoSearchType.Mix ? VideoSearchType.Videos : videoSearchType, pageNumber, pageSize)); } if (videoSearchType == VideoSearchType.Recommendation) { var search = new List <string>(); var userSearchedItem = db.Get <UserSearch>().Where(x => x.User_Id == userId).OrderByDescending(x => x.Counter).Take(1).ExecuteFirstOrDefault(); if (userSearchedItem != null) { search.Add(userSearchedItem.Text); } userSearchedItem = db.Get <UserSearch>().Where(x => x.User_Id != userId).OrderByDescending(x => x.Counter).Take(userSearchedItem == null ? 2 : 1).ExecuteFirstOrDefault(); if (userSearchedItem != null) { search.Add(userSearchedItem.Text); } result.Videos.AddRange(await m.SearchAsync($"{string.Join("|", search)} , +\"Albums\", \"Playlist\"", relatedTo, videoSearchType, pageNumber, pageSize)); } if (string.IsNullOrEmpty(relatedTo)) { if (videoSearchType == VideoSearchType.Album || videoSearchType == VideoSearchType.All) { result.Albums.AddRange(await m.SearchAsync(albumResult, relatedTo, VideoSearchType.Album, pageNumber, pageSize)); } if (videoSearchType == VideoSearchType.PlayList || videoSearchType == VideoSearchType.All) { result.Playlists.AddRange(await m.SearchAsync(playListResult, relatedTo, VideoSearchType.PlayList, pageNumber, pageSize)); } } if (!string.IsNullOrEmpty(searchString) && result.Videos.Any() && videoSearchType != VideoSearchType.Recommendation) { var item = db.Get <UserSearch>().Where(x => x.Text.Contains(searchString) && x.User_Id == userId).ExecuteFirstOrDefault() ?? new UserSearch() { Text = searchString, User_Id = userId }; item.Counter = (item.Counter ?? 0) + 1; db.Save(item).SaveChanges(); } } return(result); }