public GenericListItemCollections GetList(SiteItemEntry entry) { GenericListItemCollections res = new GenericListItemCollections(); res.Title = entry.Title; int count = 0; int ii = 0; int.TryParse(entry.GetValue("items"), out ii); for (int i = Youtube2MP._settings.SearchHistory.Count; i > 0; i--) { count++; SiteItemEntry newentry = new SiteItemEntry(); SearchVideo searchVideo = new SearchVideo(); newentry.Provider = searchVideo.Name; newentry.SetValue("term", Youtube2MP._settings.SearchHistory[i - 1]); GenericListItem listItem = new GenericListItem() { Title = "Search result for :" + Youtube2MP._settings.SearchHistory[i - 1], IsFolder = true, //LogoUrl = YoutubeGUIBase.GetBestUrl(youTubeEntry.Media.Thumbnails), Tag = newentry }; res.Items.Add(listItem); if (count > ii) break; } return res; }
/// <summary> /// 通过电影名搜索视频 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <PcCommonResults <VideoListDto> > Search(SearchVideo input) { var result = new PcCommonResults <VideoListDto>(); try { var videoList = await _context.Videos.Where(x => x.Title.Contains(input.Title)).OrderByDescending(o => o.CreateTime).ToListAsync(); if (input.ShowCount <= 0) { input.ShowCount = 30; } if (input.Page <= 0) { input.Page = 1; } // //每页尺寸 int pagSize = input.ShowCount; // //当前页 int pageCurrent = input.Page - 1; //总条数 result.Count = videoList.Count; if (result.Count == 0) { result.scode = "200"; result.remark = "查询数据成功"; result.results = null; return(result); } var videos = videoList.Select(v => new VideoListDto { Id = v.Id, Name = v.Title, Image = v.Img }); result.scode = "200"; result.remark = "查询数据成功"; result.results = videos.Skip(pageCurrent * pagSize).Take(pagSize).ToArray(); } catch (Exception ex) { result.scode = "500"; result.remark = "服务器端错误:" + ex.Message; } return(result); }
public async Task <ActionResult> SearchVideoPartial(string userId, string keyWord, int currentPage) { AppUser currentUser = userManager.Users.FirstOrDefault(u => u.Id == userId); List <SearchVideo> videos = new List <SearchVideo>(); foreach (Course course in repository.Courses.Where(c => c.Status == "Public" && (c.CreatedBy.CompanyName == currentUser.CompanyName || c.CreatedBy.CompanyName == null))) { //course video if (repository.Videos.Any(v => v.Id == course.VideoId)) { Video courseVideo = repository.Videos.FirstOrDefault(v => v.Id == course.VideoId); if (SearchWordExists(courseVideo.Title, keyWord)) { string info = $"<span class='text-muted'>For: <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchVideo searchVideoC = new SearchVideo { Video = courseVideo, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == courseVideo.CreatedBy), VideoForInfo = info }; videos.Add(searchVideoC); } } foreach (Presentation presentation in course.Presentations) { //presentation video if (repository.Videos.Any(v => v.Id == presentation.VideoId)) { Video presentationVideo = repository.Videos.FirstOrDefault(v => v.Id == presentation.VideoId); if (SearchWordExists(presentationVideo.Title, keyWord)) { string info = $"<span class='text-muted'>For: <strong>{presentation.Title}</strong> <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchVideo searchVideoP = new SearchVideo { Video = presentationVideo, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == presentationVideo.CreatedBy), VideoForInfo = info }; videos.Add(searchVideoP); } } foreach (Representation representation in presentation.Representations) { Representation repTmp = repository.Representations .FirstOrDefault(r => r.RepresentationId == representation.RepresentationId); //representation video if (repository.Videos.Any(v => v.Id == representation.VideoId)) { Video representationVideo = repository.Videos.FirstOrDefault(v => v.Id == representation.VideoId); if (SearchWordExists(representationVideo.Title, keyWord)) { if (repository.VideoShareds.Any(v => v.UserId == currentUser.Id && v.VideoId == representationVideo.Id) || await userManager.IsInRoleAsync(currentUser, "Admin") == true || await userManager.IsInRoleAsync(currentUser, "Manager") == true || representationVideo.CreatedBy == currentUser.Id) { string info = $"<span class='text-muted'>For: <strong>{representation.Title}</strong> <strong>{presentation.Title}</strong> <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchVideo searchVideoR = new SearchVideo { Video = representationVideo, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == representationVideo.CreatedBy), VideoForInfo = info }; videos.Add(searchVideoR); } } } } } } //courses where currentUser == course.CreatedBy && status == "Private" //& presentations foreach (Course course in repository.Courses.Where(c => c.Status == "Private" && (c.CreatedBy.CompanyName == currentUser.CompanyName || c.CreatedBy.CompanyName == null))) { if (course.CreatedBy != null) { if (course.CreatedBy.Id == currentUser.Id) { //course video if (repository.Videos.Any(v => v.Id == course.VideoId)) { Video courseVideo = repository.Videos.FirstOrDefault(v => v.Id == course.VideoId); if (SearchWordExists(courseVideo.Title, keyWord)) { string info = $"<span class='text-muted'>For: <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchVideo searchVideoC = new SearchVideo { Video = courseVideo, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == courseVideo.CreatedBy), VideoForInfo = info }; videos.Add(searchVideoC); } } foreach (Presentation presentation in course.Presentations) { //presentation video if (repository.Videos.Any(v => v.Id == presentation.VideoId)) { Video presentationVideo = repository.Videos.FirstOrDefault(v => v.Id == presentation.VideoId); if (SearchWordExists(presentationVideo.Title, keyWord)) { string info = $"<span class='text-muted'>For: <strong>{presentation.Title}</strong> <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchVideo searchVideoP = new SearchVideo { Video = presentationVideo, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == presentationVideo.CreatedBy), VideoForInfo = info }; videos.Add(searchVideoP); } } } } } } SearchAllVideos allVideos = new SearchAllVideos { AllVideos = videos.AsQueryable() .OrderBy(v => v.Video.Title) .Skip((currentPage - 1) * MaxSearchPageVideo) .Take(MaxSearchPageVideo), VideoPageInfo = new SearchVideoPageInfo { CurrentPage = currentPage, TotalVideos = videos.Count(), VideosPerPage = MaxSearchPageVideo } }; return(PartialView("SearchVideoPartial", allVideos)); }
public async Task <ViewResult> Search(string id, string KeyWord) { ViewData["Id"] = id; AppUser currentUser = userManager.Users.FirstOrDefault(u => u.Id == id); //users List <AppUser> users = new List <AppUser>(); foreach (AppUser user in userManager.Users.Where(u => u.CompanyName == currentUser.CompanyName)) { if (SearchWordExists(user.FirstName, KeyWord)) { users.Add(user); } else if (SearchWordExists(user.LastName, KeyWord)) { users.Add(user); } else if (SearchWordExists(user.UserName, KeyWord)) { users.Add(user); } } SearchAllUsers allUsers = new SearchAllUsers { AllUsers = users.AsQueryable().OrderBy(u => u.LastName) .Take(MaxSearchPageUsers), UserPageInfo = new SearchUserPageInfo { CurrentPage = 1, TotalUsers = users.AsQueryable().Count(), UsersPerPage = MaxSearchPageUsers } }; //courses for ALL USERS //& presentations List <SearchCourse> courses = new List <SearchCourse>(); List <SearchPresentation> presentations = new List <SearchPresentation>(); List <SearchRepresentation> representations = new List <SearchRepresentation>(); List <SearchVideo> videos = new List <SearchVideo>(); List <SearchFiles> files = new List <SearchFiles>(); foreach (Course course in repository.Courses.Where(c => c.Status == "Public" && (c.CreatedBy.CompanyName == currentUser.CompanyName || c.CreatedBy.CompanyName == null))) { if (SearchWordExists(course.Title, KeyWord)) { SearchCourse searchCourse = new SearchCourse { Course = course, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == course.CreatedBy.Id) }; courses.Add(searchCourse); } //course video if (repository.Videos.Any(v => v.Id == course.VideoId)) { Video courseVideo = repository.Videos.FirstOrDefault(v => v.Id == course.VideoId); if (SearchWordExists(courseVideo.Title, KeyWord)) { string info = $"<span class='text-muted'>For: <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchVideo searchVideoC = new SearchVideo { Video = courseVideo, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == courseVideo.CreatedBy), VideoForInfo = info }; videos.Add(searchVideoC); } } foreach (Presentation presentation in course.Presentations) { if (SearchWordExists(presentation.Title, KeyWord)) { SearchPresentation searchPresentation = new SearchPresentation { Presentation = presentation, Course = course, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == course.CreatedBy.Id) }; presentations.Add(searchPresentation); } //presentation video if (repository.Videos.Any(v => v.Id == presentation.VideoId)) { Video presentationVideo = repository.Videos.FirstOrDefault(v => v.Id == presentation.VideoId); if (SearchWordExists(presentationVideo.Title, KeyWord)) { string info = $"<span class='text-muted'>For: <strong>{presentation.Title}</strong> <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchVideo searchVideoP = new SearchVideo { Video = presentationVideo, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == presentationVideo.CreatedBy), VideoForInfo = info }; videos.Add(searchVideoP); } } //presentation files foreach (PresentationFiles file1 in repository.PresentationFiles .Where(f => f.PresentationId == presentation.PresentationId)) { if (SearchWordExists(file1.Title, KeyWord)) { string info = $"<span class='text-muted'>For: <strong>{presentation.Title}</strong> <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchFiles searchFile1 = new SearchFiles { File = file1, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == presentation.CreatedBy.Id), FileForInfo = info }; files.Add(searchFile1); } } foreach (Representation representation in presentation.Representations) { if (SearchWordExists(representation.Title, KeyWord)) { SearchRepresentation searchRepresentation = new SearchRepresentation { Representation = representation, PresentationTitle = presentation.Title, Course = course, Video = repository.Videos.FirstOrDefault(v => v.Id == representation.VideoId), CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == representation.CreatedBy.Id) }; representations.Add(searchRepresentation); } //representation video if (repository.Videos.Any(v => v.Id == representation.VideoId)) { Video representationVideo = repository.Videos.FirstOrDefault(v => v.Id == representation.VideoId); if (SearchWordExists(representationVideo.Title, KeyWord)) { if (repository.VideoShareds.Any(v => v.UserId == currentUser.Id && v.VideoId == representationVideo.Id) || await userManager.IsInRoleAsync(currentUser, "Admin") == true || await userManager.IsInRoleAsync(currentUser, "Manager") == true || representationVideo.CreatedBy == currentUser.Id) { string info = $"<span class='text-muted'>For: <strong>{representation.Title}</strong> <strong>{presentation.Title}</strong> <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchVideo searchVideoR = new SearchVideo { Video = representationVideo, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == representationVideo.CreatedBy), VideoForInfo = info }; videos.Add(searchVideoR); } } } } } } //courses where currentUser == course.CreatedBy && status == "Private" //& presentations foreach (Course course in repository.Courses.Where(c => c.Status == "Private" && (c.CreatedBy.CompanyName == currentUser.CompanyName || c.CreatedBy.CompanyName == null))) { if (course.CreatedBy != null) { if (course.CreatedBy.Id == currentUser.Id) { if (SearchWordExists(course.Title, KeyWord)) { SearchCourse searchCourse = new SearchCourse { Course = course, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == course.CreatedBy.Id) }; courses.Add(searchCourse); } //course video if (repository.Videos.Any(v => v.Id == course.VideoId)) { Video courseVideo = repository.Videos.FirstOrDefault(v => v.Id == course.VideoId); if (SearchWordExists(courseVideo.Title, KeyWord)) { string info = $"<span class='text-muted'>For: <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchVideo searchVideoC = new SearchVideo { Video = courseVideo, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == courseVideo.CreatedBy), VideoForInfo = info }; videos.Add(searchVideoC); } } foreach (Presentation presentation in course.Presentations) { if (SearchWordExists(presentation.Title, KeyWord)) { SearchPresentation searchPresentation = new SearchPresentation { Presentation = presentation, Course = course, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == course.CreatedBy.Id) }; presentations.Add(searchPresentation); } //presentation video if (repository.Videos.Any(v => v.Id == presentation.VideoId)) { Video presentationVideo = repository.Videos.FirstOrDefault(v => v.Id == presentation.VideoId); if (SearchWordExists(presentationVideo.Title, KeyWord)) { string info = $"<span class='text-muted'>For: <strong>{presentation.Title}</strong> <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchVideo searchVideoP = new SearchVideo { Video = presentationVideo, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == presentationVideo.CreatedBy), VideoForInfo = info }; videos.Add(searchVideoP); } } //presentation files foreach (PresentationFiles file2 in repository.PresentationFiles .Where(f => f.PresentationId == presentation.PresentationId)) { if (SearchWordExists(file2.Title, KeyWord)) { string info = $"<span class='text-muted'>For: <strong>{presentation.Title}</strong> <i class='{course.AwardIcon}'></i>" + $"<strong>{course.Title}</strong></span>"; SearchFiles searchFile2 = new SearchFiles { File = file2, CreatedBy = userManager.Users.FirstOrDefault(u => u.Id == presentation.CreatedBy.Id), FileForInfo = info }; files.Add(searchFile2); } } } } } } SearchAllCourses allCourses = new SearchAllCourses { AllCourses = courses.AsQueryable().OrderBy(c => c.Course.Title) .Take(MaxSearchPageCourse), CoursePageInfo = new SearchCoursePageInfo { CurrentPage = 1, TotalCourses = courses.AsQueryable().Count(), CoursesPerPage = MaxSearchPageCourse } }; SearchAllPresentation allPresentation = new SearchAllPresentation { AllPresentations = presentations.AsQueryable() .OrderBy(p => p.Presentation.Title) .Take(MaxSearchPagePresentation), PresentationPageInfo = new SearchPresentationPageInfo { CurrentPage = 1, TotalPresentations = presentations.AsQueryable().Count(), PresentationsPerPage = MaxSearchPagePresentation } }; SearchAllRepresentation allRepresentation = new SearchAllRepresentation { AllRepresentation = representations.AsQueryable() .OrderBy(r => r.Representation.Title) .Take(MaxSearchPageRepresentation), RepresentationPageInfo = new SearchRepresentationPageInfo { CurrentPage = 1, TotalRepresentation = representations.AsQueryable().Count(), RepresentationPerPage = MaxSearchPageRepresentation } }; SearchAllVideos allVideos = new SearchAllVideos { AllVideos = videos.AsQueryable() .OrderBy(v => v.Video.Title) .Take(MaxSearchPageVideo), VideoPageInfo = new SearchVideoPageInfo { CurrentPage = 1, TotalVideos = videos.Count(), VideosPerPage = MaxSearchPageVideo } }; SearchAllFiles allFiles = new SearchAllFiles { AllFiles = files.AsQueryable() .OrderBy(f => f.File.Title) .Take(MaxSearchPageFile), FilePageInfo = new SearchFilesPageInfo { CurrentPage = 1, TotalFiles = files.Count(), FilesPerPage = MaxSearchPageFile } }; return(View("Search", new SearchViewModel { KeyWord = KeyWord, Users = allUsers, Courses = allCourses, Presentations = allPresentation, Representations = allRepresentation, Videos = allVideos, Files = allFiles })); }
public async Task <PcCommonResults <VideoListDto> > Search([FromBody] SearchVideo input) { var videos = await _videoService.Search(input); return(videos); }