예제 #1
0
        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();
            }
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
 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();
     }
 }
예제 #5
0
        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();
            }
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
        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);
            }
        }