public async Task <IEnumerable <CategoryDTO> > GetAllCategoriesAsync(string culture) { using (var db = new myDb()) { if (culture == "cs-CZ") { return(await db.Categories .Select(x => new CategoryDTO() { Id = x.Id, Name = x.Name, Img = "Admin/CategoryImg/" + x.Img }).OrderBy(p => p.Name).ToListAsync()); } else { return(await db.Categories .Select(x => new CategoryDTO() { Id = x.Id, Name = x.Name_en, Img = "Admin/CategoryImg/" + x.Img }).OrderBy(p => p.Name).ToListAsync()); } } }
public async Task <IEnumerable <string> > GetCategoriesAsync() { using (var db = new myDb()) { return(await db.Categories.OrderBy(p => p.Name) .Select(x => x.Name).ToListAsync()); } }
public async Task <int> GetCategoryVideosCount(int Id) { using (var db = new myDb()) { return(await db.Videos .Where(x => x.Categories.Select(p => p.Id).Contains(Id)) .CountAsync()); } }
public async Task RemoveCategoryAsync(int Id) { using (var db = new myDb()) { var category = await db.Categories.FindAsync(Id); db.Categories.Remove(category); await db.SaveChangesAsync(); } }
public GridViewDataSetLoadedData <VideoListDTO> GetAllVideos(IGridViewDataSetLoadOptions gridViewDataSetLoadOptions, bool loadmobile, int specific, string culture) { using (var db = new myDb()) { IQueryable <Video> query = db.Videos.Where(x => x.AllowMain == true); if (specific == 0) //nejnovejsi { query = query.OrderByDescending(x => x.Id); if (loadmobile) //videa pouze pro mobil { query = query.Where(p => p.Url.Contains("pornhub")); } } else //nejsledovanejsi videa { query = query.OrderByDescending(x => x.Views); if (loadmobile) // nejsledovanejsi videa pouze pro mobil { query = query.Where(p => p.Url.Contains("pornhub")); } } IQueryable <VideoListDTO> finalquery; if (culture == "cs-CZ") { finalquery = query // finalni poskladana query .Select(a => new VideoListDTO { Id = a.Id, Img = "Admin/Previews/" + a.Img, Title = a.Title, Duration = a.Duration, HD = a.HD, Preview = "Admin/Previews/" + a.Preview, Views = a.Views, TimeStamp = a.TimeStamp }).AsQueryable(); } else { finalquery = query // finalni poskladana query .Select(a => new VideoListDTO { Id = a.Id, Img = "Admin/Previews/" + a.Img, Title = a.Title_en, Duration = a.Duration, HD = a.HD, Preview = "Admin/Previews/" + a.Preview, Views = a.Views, TimeStamp = a.TimeStamp }).AsQueryable(); } return(finalquery.GetDataFromQueryable(gridViewDataSetLoadOptions)); } }
public async Task UpdateCategoryAsync(CategoryDTO category) { using (var db = new myDb()) { var dbCat = await db.Categories.FindAsync(category.Id); dbCat.Name = category.Name; dbCat.Name_en = category.Name_en; await db.SaveChangesAsync(); } }
public async Task <IEnumerable <VideoListDTO> > GetRecommendedVideosAsync(string culture) { if (HttpContext.Current.Request.Cookies["CategoryCount"] != null) { List <string> categories = HttpContext.Current.Request.Cookies["CategoryCount"].Value .Split(':') .Take(2) .Select(x => x.ToString().Split(',')[0]).ToList(); try { using (var db = new myDb()) { var predicate = PredicateBuilder.New <Video>(); foreach (string item in categories) { int Id = Convert.ToInt32(item); predicate = predicate.Or(x => x.Categories.Any(p => p.Id == Id)); } int count = db.Videos.AsExpandable().Where(predicate).Count(); if (count > 3) //personalizovane vysledky { int skip = GetRandomNumber(count); IQueryable <Video> query = db.Videos.AsExpandable().Where(predicate); return(await GetRecommendedVideosDataAsync(query, culture)); } else //random videa { IQueryable <Video> query; query = db.Videos.Where(x => x.AllowMain); return(await GetRecommendedVideosDataAsync(query, culture)); } } } catch { using (var db = new myDb()) { HttpContext.Current.Response.Cookies["CategoryCount"].Expires = DateTime.Now.AddDays(-1); IQueryable <Video> query = db.Videos; return(await GetRecommendedVideosDataAsync(query, culture)); } } } else //random videa { using (var db = new myDb()) { IQueryable <Video> query; query = db.Videos.Where(x => x.AllowMain); return(await GetRecommendedVideosDataAsync(query, culture)); } } }
public GridViewDataSetLoadedData <VideoListDTO> GetVideosByCategory(IGridViewDataSetLoadOptions gridViewDataSetLoadOptions, int Id, int specific, bool loadmobile, string culture) { using (var db = new myDb()) { IQueryable <Video> query = db.Videos.Where(x => x.Categories.Select(p => p.Id).Contains(Id)); if (specific == 0) //nejnovejsi { query = query.OrderByDescending(x => x.Id); if (loadmobile) //videa pouze pro mobil { query = query.Where(p => p.Url.Contains("pornhub")); } } else //nejsledovanejsi videa { query = query.OrderByDescending(x => x.Views); if (loadmobile) // nejsledovanejsi videa pouze pro mobil { query = query.Where(p => p.Url.Contains("pornhub")); } } IQueryable <VideoListDTO> finalquery; if (culture == "cs-CZ") { finalquery = query.Select(x => new VideoListDTO() { Id = x.Id, Img = "Admin/Previews/" + x.Img, Title = x.Title, Duration = x.Duration, HD = x.HD, Preview = "Admin/Previews/" + x.Preview, }).AsQueryable(); return(finalquery.GetDataFromQueryable(gridViewDataSetLoadOptions)); } else { finalquery = query.Select(x => new VideoListDTO() { Id = x.Id, Img = "Admin/Previews/" + x.Img, Title = x.Title_en, Duration = x.Duration, HD = x.HD, Preview = "Admin/Previews/" + x.Preview, }).AsQueryable(); return(finalquery.GetDataFromQueryable(gridViewDataSetLoadOptions)); } } }
public async Task RemoveVideoAsync(int Id) { using (var db = new myDb()) { var video = await db.Videos.FindAsync(Id); db.Comments.RemoveRange(video.Comments); //string downloadPath = GetDownloadPath(); //File.Delete(downloadPath + "/" + video.Img); //File.Delete(downloadPath + "/" + video.Preview); db.Videos.Remove(video); await db.SaveChangesAsync(); } }
public bool VideoExists(string url) { using (var db = new myDb()) { if (db.Videos.Where(x => x.Url == url).Count() != 0) { return(true); } else { return(false); } } }
public bool CategoryExists(CategoryDTO cat) { using (var db = new myDb()) { int check = db.Categories .Where(x => x.Name == cat.Name && x.Name_en == cat.Name_en).Count(); if (check > 0) { return(true); } else { return(false); } } }
public async Task AddCategoryAsync(CategoryDTO category, string username) { using (var db = new myDb()) { var user = db.Users .Where(x => x.Username == username) .First(); Category dbCat = new Category(); dbCat.Name = category.Name; dbCat.Name_en = category.Name_en; dbCat.User = user; dbCat.Img = "placeholder.jpg"; db.Categories.Add(dbCat); await db.SaveChangesAsync(); } }
private IEnumerable <string> GetImages(string category) { using (var db = new myDb()) { //var query = db.Videos.Where(x=>x.Categories.Select(p=>p.Name).Contains(category)); //var query = db.Videos.OrderByDescending(p => p.Id) // .Select(x => x.Img).Take(50).ToList(); IQueryable <Video> query = db.Videos; if (!string.IsNullOrEmpty(category)) { query = query.Where(x => x.Categories.Select(p => p.Name_en.ToLower()).Contains(category)); } return(query .OrderByDescending(p => p.Id) .Select(x => x.Img).Take(200).ToList()); } }
public async Task AddVideoAsync(VideoAdminDTO vid, string username) { var downloadPath = GetDownloadPath(); var previewfileName = GetVideoFileName(vid.Preview); var imgfileName = GetVideoFileName(vid.Img); using (var client = new WebClient()) { client.DownloadFile(vid.Preview, downloadPath + "/" + previewfileName); client.DownloadFile(vid.Img, downloadPath + "/" + imgfileName); } Video video = new Video(); video.Description = vid.Description; video.Title = vid.Title; video.Title_en = vid.Title_en; video.Url = vid.Url; video.Img = imgfileName; video.TimeStamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); //var ffMpeg = new NReco.VideoConverter.FFMpegConverter(); //string mp4Name = ChangeNameToMp4(previewfileName); //ffMpeg.ConvertMedia(downloadPath + "/" + previewfileName, downloadPath + "/" + "test.mp4", Format.mp4); //File.Delete(downloadPath + "/" + previewfileName); video.Preview = previewfileName; video.HD = vid.HD; video.Duration = vid.Duration; video.AllowMain = vid.AllowMain; using (var db = new myDb()) { var user = db.Users.Where(x => x.Username == username).First(); video.User = user; foreach (CategoryDTO item in vid.Categories) { Category tag = await db.Categories .Where(x => x.Name == item.Name) .FirstAsync(); video.Categories.Add(tag); } db.Videos.Add(video); await db.SaveChangesAsync(); } }
public GridViewDataSetLoadedData <CategoryDTO> GetAllCategories(IGridViewDataSetLoadOptions gridViewDataSetLoadOptions, string username) { using (var db = new myDb()) { IQueryable <Category> query = db.Categories; if (username != "kelt" && username != "brych") { query = query.Where(x => x.User.Username == username); } var finalQuery = query .Select(p => new CategoryDTO() { Id = p.Id, Name = p.Name, Name_en = p.Name_en }).OrderByDescending(a => a.Id).AsQueryable(); return(finalQuery.GetDataFromQueryable(gridViewDataSetLoadOptions)); } }
public GridViewDataSetLoadedData <VideoListAdminDTO> GetAllVideos(IGridViewDataSetLoadOptions gridViewDataSetLoadOptions, string username) { using (var db = new myDb()) { IQueryable <Video> query = db.Videos; if (username != "kelt" && username != "brych") { query = query.Where(x => x.User.Username == username); } var finalQuery = query.Select(x => new VideoListAdminDTO() { Id = x.Id, Img = "Admin/Previews/" + x.Img, Title = x.Title, Preview = "Admin/Previews/" + x.Preview, }).OrderByDescending(p => p.Id).AsQueryable(); return(finalQuery.GetDataFromQueryable(gridViewDataSetLoadOptions)); } }
public async Task <bool> UserExist(string username, string password) { using (var db = new myDb()) { string shaPassword = sha256(password); var user = await db.Users .Where(x => x.Username == username && x.Password == shaPassword) .FirstOrDefaultAsync(); if (user != null) { return(true); } else { return(false); } } }
public async Task UpdateVideoAsync(VideoAdminDTO video) { using (var db = new myDb()) { var dbVideo = db.Videos.Find(video.Id); dbVideo.Title = video.Title; dbVideo.Description = video.Description; dbVideo.Img = video.Img; dbVideo.Preview = video.Preview; dbVideo.Url = video.Url; dbVideo.AllowMain = video.AllowMain; dbVideo.Categories.Clear(); foreach (CategoryDTO item in video.Categories) { var category = await db.Categories.Where(x => x.Name == item.Name).FirstAsync(); dbVideo.Categories.Add(category); } await db.SaveChangesAsync(); } }
public async Task <VideoDetailDTO> GetVideoByIdAsync(int Id, string culture) { using (var db = new myDb()) { db.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); Video video = await db.Videos.FindAsync(Id); video.Views++; await db.SaveChangesAsync(); VideoDetailDTO vid = new VideoDetailDTO(); vid.Id = video.Id; vid.Img = video.Img; if (culture == "cs-CZ") { vid.Title = video.Title; vid.Categories = video.Categories.Select(x => new CategoryDTO() { Id = x.Id, Name = x.Name }).ToList(); } else { vid.Title = video.Title_en; vid.Categories = video.Categories.Select(x => new CategoryDTO() { Id = x.Id, Name = x.Name_en }).ToList(); } vid.Url = video.Url; vid.Views = video.Views; db.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); CookieRepository CookieRep = new CookieRepository(); CookieRep.UpdateCategoryCookie(vid.Categories); CookieRep.UpdateHistoryCookie(video.Id.ToString()); return(vid); } }
public async Task <int> GetSearchResultCount(string search, string culture) { using (var db = new myDb()) { if (culture == "cs-CZ") { return(await db.Videos .Where(x => x.Title .Contains(search) || x.Categories .Any(p => p.Name.Contains(search)) || x.Categories .Any(o => o.Name_en.Contains(search))).CountAsync()); } else { return(await db.Videos .Where(x => x.Title_en .Contains(search) || x.Categories .Any(p => p.Name.Contains(search)) || x.Categories .Any(o => o.Name_en.Contains(search))).CountAsync()); } } }
public async Task <VideoAdminDTO> GetVideoByIdAsync(int Id) { using (var db = new myDb()) { return(await db.Videos. Where(x => x.Id == Id) .Select(p => new VideoAdminDTO { Id = p.Id, Description = p.Description, Img = p.Img, Preview = p.Preview, Title = p.Title, Title_en = p.Title_en, Url = p.Url, AllowMain = p.AllowMain, Categories = p.Categories.Select(x => new CategoryDTO() { Name = x.Name, Name_en = x.Name_en }) }).FirstOrDefaultAsync()); } }
public GridViewDataSetLoadedData <VideoListDTO> GetSearchResult(IGridViewDataSetLoadOptions gridViewDataSetLoadOptions, string search, bool loadmomobile, int specific, string culture) { using (var db = new myDb()) { IQueryable <Video> query = db.Videos; if (specific == 0) // nejnovejsi { query = query.OrderByDescending(x => x.Id); if (loadmomobile) // videa pouze pro mobil { query = query.Where(p => p.Url.Contains("pornhub")); } } else // nejsledovanejsi { query = query.OrderByDescending(x => x.Views); if (loadmomobile) // nejsledovanejsi videa pouze pro mobil { query = query.Where(p => p.Url.Contains("pornhub")); } } IQueryable <VideoListDTO> finalquery; if (culture == "cs-CZ") { query = query.Where(x => x.Title .Contains(search) || x.Categories .Any(p => p.Name.Contains(search)) || x.Categories .Any(o => o.Name_en.Contains(search))); finalquery = query // finalni poskladana query .Select(a => new VideoListDTO { Id = a.Id, Img = "Admin/Previews/" + a.Img, Title = a.Title, Duration = a.Duration, HD = a.HD, Preview = "Admin/Previews/" + a.Preview, Views = a.Views }).AsQueryable(); } else { query = query.Where(x => x.Title_en .Contains(search) || x.Categories .Any(p => p.Name.Contains(search)) || x.Categories .Any(o => o.Name_en.Contains(search))); finalquery = query // finalni poskladana query .Select(a => new VideoListDTO { Id = a.Id, Img = "Admin/Previews/" + a.Img, Title = a.Title_en, Duration = a.Duration, HD = a.HD, Preview = "Admin/Previews/" + a.Preview, Views = a.Views }).AsQueryable(); } return(finalquery.GetDataFromQueryable(gridViewDataSetLoadOptions)); } }
public async Task <IEnumerable <VideoListDTO> > GetSuggestedVideosAsync(List <int> Categories, int Id, string culture) { List <string> CategoriesCounts = new List <string>(); if (Categories.Count > 2) { var result = GetPermutations(Categories, 3); using (var db = new myDb()) { foreach (var perm in result) { List <int> Combination = new List <int>(); foreach (var item in perm) { Combination.Add(Convert.ToInt32(item)); } int a = Combination[0]; int b = Combination[1]; int c = Combination[2]; int count = db.Videos.Where(x => x.Categories.Any(p => p.Id == a) && x.Categories.Any(o => o.Id == b) && x.Categories.Any(k => k.Id == c) && x.Id != Id).Count(); CategoriesCounts.Add(a + ";" + b + ";" + c + ":" + count); } List <int> finalResult = GetHighestCategoryCount(CategoriesCounts); if (finalResult[3] > 0) { int first = finalResult[0]; int second = finalResult[1]; int third = finalResult[2]; if (culture == "cs-CZ") { return(await db.Videos.Where(x => x.Categories.Any(p => p.Id == first) && x.Categories.Any(o => o.Id == second) && x.Categories.Any(k => k.Id == third) && x.Id != Id) .Select(p => new VideoListDTO { Id = p.Id, Title = p.Title, Img = "Admin/Previews/" + p.Img, Preview = "Admin/Previews/" + p.Preview, Duration = p.Duration, HD = p.HD }).Take(6).ToListAsync()); } else { return(await db.Videos.Where(x => x.Categories.Any(p => p.Id == first) && x.Categories.Any(o => o.Id == second) && x.Categories.Any(k => k.Id == third) && x.Id != Id) .Select(p => new VideoListDTO { Id = p.Id, Title = p.Title_en, Img = "Admin/Previews/" + p.Img, Preview = "Admin/Previews/" + p.Preview, Duration = p.Duration, HD = p.HD }).Take(6).ToListAsync()); } } else { List <VideoListDTO> videos = new List <VideoListDTO>(); return(videos); } } } else { using (var db = new myDb()) { IQueryable <Video> query = db.Videos; foreach (int item in Categories) { query = query.Where(x => x.Categories.Any(p => p.Id == item)); } return(await query.Where(x => x.Id != Id) .Select(p => new VideoListDTO { Id = p.Id, Title = p.Title, Img = "Admin/Previews/" + p.Img, Preview = "Admin/Previews/" + p.Preview, Duration = p.Duration, HD = p.HD }).Take(6).ToListAsync()); } } }
public async Task <List <VideoListDTO> > GetVideoHistoryAsync(string culture) { if (HttpContext.Current.Request.Cookies["History"] != null) { string[] array = HttpContext.Current.Request.Cookies["History"].Value.Split(','); if (array.Length < 5) { using (var db = new myDb()) { var predicate = PredicateBuilder.New <Video>(); foreach (string item in array) { try { int Id = Convert.ToInt32(item); predicate = predicate.Or(x => x.Id == Id); } catch { HttpContext.Current.Response.Cookies["History"].Expires = DateTime.Now.AddDays(-1); break; } } if (culture == "cs-CZ") { return(await db.Videos.AsExpandable() .Where(predicate) .Select(a => new VideoListDTO() { Id = a.Id, Img = "Admin/Previews/" + a.Img, Title = a.Title, Duration = a.Duration, HD = a.HD, Preview = "Admin/Previews/" + a.Preview }).ToListAsync()); } else { return(await db.Videos.AsExpandable() .Where(predicate) .Select(a => new VideoListDTO() { Id = a.Id, Img = "Admin/Previews/" + a.Img, Title = a.Title_en, Duration = a.Duration, HD = a.HD, Preview = "Admin/Previews/" + a.Preview }).ToListAsync()); } } } else { HttpContext.Current.Response.Cookies["History"].Expires = DateTime.Now.AddDays(-1); return(new List <VideoListDTO>()); } } else { return(new List <VideoListDTO>()); } }