Ejemplo n.º 1
0
 //GET: /Video/Created
 public ActionResult Created(VideoFileItem viewModel)
 {
     using (var dataBase = new ApplicationDbContext())
     {
         return(View(viewModel));
     }
 }
Ejemplo n.º 2
0
        public ActionResult Delete(VideoFileItem model)
        {
            model.IsDeleted = true;

            using (var dataBase = new ApplicationDbContext())
            {
                var videoFileItemForDelete = dataBase.Video.SingleOrDefault(VideoFileItem => VideoFileItem.Id == model.Id);
                if (videoFileItemForDelete != null)
                {
                    videoFileItemForDelete.IsDeleted = true;
                    dataBase.SaveChanges();

                    var serverPath = Server.MapPath(videoFileItemForDelete.FilePath);
                    if (System.IO.File.Exists(serverPath))
                    {
                        System.IO.File.Delete(serverPath);
                    }

                    model = videoFileItemForDelete;
                }
            }

            //Successfully deleted
            return(View("Deleted", model));
        }
Ejemplo n.º 3
0
        private void ReloadFileList(string fullPath)
        {
            _logger.LogTrace($"{App.GetCaller()}() entered");

            bool foundVideos     = false;
            var  videoExtensions = _appSettings.VideoExtensions.Split(',').Select(p => p.Trim().ToUpper()).ToList();

            _vm.FileList = new ObservableCollection <VideoFileItem>();

            foreach (string f in Directory.GetFiles(fullPath))
            {
                // Only display valid video files
                if (videoExtensions.Contains(System.IO.Path.GetExtension(f).ToUpper()))
                {
                    foundVideos = true;
                    var fileItem = new VideoFileItem()
                    {
                        ImageSource = "/Images/video.png",
                        FullPath    = f,
                        Text        = Path.GetFileName(f)
                    };

                    // Determine whether this video has subtitles
                    _appSettings = _services.GetRequiredService <IWritableOptions <AppSettings> >().Value;

                    if (fileItem.GenerateSubtitleInfo(_appSettings.DefaultLanguage, _allCultureInfos) == true)
                    {
                        _vm.FileList.Add(fileItem);
                    }
                    else
                    {
                        _logger.LogError($"Unable to look up culture info for language '{_appSettings.DefaultLanguage}'");
                    }
                }
            }

            if (!foundVideos)
            {
                var notFoundItem = new VideoFileItem()
                {
                    Text = $"(No videos were found in folder '{new DirectoryInfo(fullPath).Name}')"
                };

                _vm.FileList.Add(notFoundItem);
            }

            _logger.LogTrace($"{App.GetCaller()}() exiting");
        }
Ejemplo n.º 4
0
        public ActionResult Edit(VideoFileItem viewModel, HttpPostedFileBase uploadVideoFile)
        {
            using (var dataBase = new ApplicationDbContext())
            {
                var itemForEdit = dataBase.Video.SingleOrDefault(item => item.Id == viewModel.Id);
                if (itemForEdit != null)
                {
                    if (uploadVideoFile != null)
                    {
                        string fileName = Path.GetFileName(uploadVideoFile.FileName);
                        int    fileSize = uploadVideoFile.ContentLength;

                        var filePath = "~/VideoFileUpload/" + fileName;
                        uploadVideoFile.SaveAs(Server.MapPath(filePath));

                        viewModel.Name     = fileName;
                        viewModel.FilePath = filePath;
                        viewModel.FileSize = fileSize;
                    }
                    else
                    {
                        viewModel.Name     = itemForEdit.Name;
                        viewModel.FilePath = itemForEdit.FilePath;
                        viewModel.FileSize = itemForEdit.FileSize;
                    }

                    itemForEdit.IsDeleted   = false;
                    itemForEdit.Title       = viewModel.Title;
                    itemForEdit.Description = viewModel.Description;
                    itemForEdit.Name        = viewModel.Name;
                    itemForEdit.FilePath    = viewModel.FilePath;
                    itemForEdit.FileSize    = viewModel.FileSize;
                    dataBase.SaveChanges();
                }
            }

            //Successfully deleted
            return(View("Modified", viewModel));
        }
Ejemplo n.º 5
0
        public ActionResult Add(VideoFileItem viewModel, HttpPostedFileBase uploadVideoFile)
        {
            var videoFileItem = new VideoFileItem();

            if (ModelState.IsValid)
            {
                using (var dataBase = new ApplicationDbContext())
                {
                    if (uploadVideoFile != null)
                    {
                        string fileName = Path.GetFileName(uploadVideoFile.FileName);
                        int    fileSize = uploadVideoFile.ContentLength;

                        var filePath           = "~/VideoFileUpload/" + fileName;
                        var serverPath         = Server.MapPath(filePath);
                        var directoryWithVideo = Path.GetDirectoryName(serverPath);
                        if (!new DirectoryInfo(directoryWithVideo).Exists)
                        {
                            Directory.CreateDirectory(directoryWithVideo);
                        }

                        uploadVideoFile.SaveAs(serverPath);

                        videoFileItem.Name        = fileName;
                        videoFileItem.FilePath    = filePath;
                        videoFileItem.FileSize    = fileSize;
                        videoFileItem.Title       = viewModel.Title;
                        videoFileItem.Description = viewModel.Description;
                        videoFileItem.IsDeleted   = false;
                        dataBase.Video.Add(videoFileItem);
                        dataBase.SaveChanges();
                    }
                }
            }

            //Successfully created
            return(View("Created", videoFileItem));
        }
Ejemplo n.º 6
0
        public ActionResult Add()
        {
            var viewModel = new VideoFileItem();

            return(View(viewModel));
        }