Ejemplo n.º 1
0
        public ActionResult Delete(int id)
        {
            try
            {
                IVideosService videoSrv = IoC.Resolve <IVideosService>();
                Videos         video    = videoSrv.Getbykey(id);
                string[]       vpath    = video.VideoPath.Split('/');
                var            filePath = ConfigurationSettings.AppSettings.Get("PhysicalSiteDataDirectory") + "/video/" + vpath[vpath.Length - 1];

                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                }
                videoSrv.Delete(video);
                videoSrv.CommitChanges();
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Delete : " + id, "Delete Video Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                Messages.AddFlashMessage("Xóa thành công.");
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Delete : " + id, "Delete Video Error : " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                Messages.AddErrorMessage("Chưa xóa được, vui lòng thực hiện lại.");
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult ConfirmUpload(Videos video)
        {
            try
            {
                IVideosService videoSrv = IoC.Resolve <IVideosService>();
                video.LinkType  = LinkType.Local;
                video.CreatedBy = HttpContext.User.Identity.Name;
                video.VideoPath = "/VideosStore/video/" + video.VideoPath;
                //Hình ảnh

                video.URLName = FX.Utils.Common.TextHelper.ToUrlFriendly(video.NameVNI);
                ConvertVideo conv = new ConvertVideo(video.VideoPath);
                if (video.VideoPath.IndexOf("mp4") > 0)
                {
                    Thread thread = new Thread(new ThreadStart(conv.ConvertVideoToWebM));
                    thread.Start();
                }
                else if (video.VideoPath.IndexOf("webm") > 0)
                {
                    Thread thread = new Thread(new ThreadStart(conv.ConvertVideoToMp4));
                    thread.Start();
                }


                string videoFull = video.VideoPath.Split('/')[3];
                string videoName = videoFull.Split('.')[0];
                string imageName = "/UploadStore/Videos/" + videoName + ".jpg";

                video.ImagePath = imageName;
                videoSrv.CreateNew(video);
                videoSrv.CommitChanges();
                Messages.AddFlashMessage("Thêm mới thành công.");
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Create", "Create Video Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);

                return(new JsonResult()
                {
                    Data = "Tải Video thành công!"
                });
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Create", "Create Video Error : " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);

                return(new JsonResult()
                {
                    Data = "Có lỗi xảy ra vui lòng thực hiện lại."
                });
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(Videos video)
        {
            try
            {
                IVideosService videoSrv = IoC.Resolve <IVideosService>();
                video.CreatedBy = HttpContext.User.Identity.Name;
                video.ImagePath = "/UploadStore/Videos/video.jpg";
                video.LinkType  = LinkType.Youtube;
                //Kiểm tra video đường dẫn video chuẩn chưa .
                if (video.VideoPath.IndexOf("embed") <= 0)
                {
                    string[] arr = video.VideoPath.Split('=');
                    string   yId = arr[1];
                    if (yId.Length > 0)
                    {
                        string convertToEmbedLink = "https://www.youtube.com/embed/" + yId;
                        video.VideoPath = convertToEmbedLink;
                        //Định dạng chuẩn để xem video = thẻ iframe

                        WebClient cli = new WebClient();

                        var imgBytes = cli.DownloadData("http://img.youtube.com/vi/" + yId + "/0.jpg");

                        // System.IO.File.WriteAllBytes(ConfigurationSettings.AppSettings.Get("PhysicalSiteDataDirectory") + @"\_thumbs\Videos\" + yId + ".jpg", imgBytes);
                        video.ImagePath = "/UploadStore/Videos/" + yId + ".jpg";
                    }
                }

                video.URLName = FX.Utils.Common.TextHelper.ToUrlFriendly(video.NameVNI);
                videoSrv.CreateNew(video);
                videoSrv.CommitChanges();
                Messages.AddFlashMessage("Thêm mới thành công.");
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Create", "Create Video Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Create", "Create Video Error : " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);

                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                IVideoTypeService videoTypeSrv = IoC.Resolve <IVideoTypeService>();
                VideoModels       model        = new VideoModels();
                model.Video      = video;
                model.VideoTypes = videoTypeSrv.Query.Where(p => p.Active).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList();
                return(View(model));
            }
        }
Ejemplo n.º 4
0
        public ActionResult Edit(Videos video)
        {
            IVideosService videoSrv = IoC.Resolve <IVideosService>();

            //Videos oldVideo = videoSrv.Getbykey(video.Id);
            try
            {
                TryUpdateModel <Videos>(video);
                video.ModifiedBy   = HttpContext.User.Identity.Name;
                video.ModifiedDate = DateTime.Now;
                //Kiểm trra người dùng có thực hiện đăng video mới thay thế hay không
                //if (video.VideoPath != oldVideo.VideoPath)
                //{
                if (video.LinkType == LinkType.Youtube)
                {
                    byte[]    imgBytes;
                    string    yId;
                    WebClient cli = new WebClient();
                    if (video.VideoPath.IndexOf("embed") <= 0)
                    {
                        string[] arr = video.VideoPath.Split('=');
                        yId = arr[1];
                        string convertToEmbedLink = "https://www.youtube.com/embed/" + yId;
                        video.VideoPath = convertToEmbedLink;
                        imgBytes        = cli.DownloadData("http://img.youtube.com/vi/" + yId + "/0.jpg");
                    }
                    else
                    {
                        string[] arr = video.VideoPath.Split('/');
                        yId = arr[arr.Length - 1];
                    }

                    imgBytes = cli.DownloadData("http://img.youtube.com/vi/" + yId + "/0.jpg");
                    System.IO.File.WriteAllBytes(ConfigurationSettings.AppSettings.Get("PhysicalSiteDataDirectory") + @"\_thumbs\Videos\" + yId + ".jpg", imgBytes);
                    video.ImagePath = "/UploadStore/Videos/" + yId + ".jpg";
                }
                else
                {
                    //Sửa video tự tự upload thì tiến hành convert video vừa sửa sang mp4 hoặc webm
                    ConvertVideo conv = new ConvertVideo(video.VideoPath);
                    if (video.VideoPath.IndexOf("mp4") > 0)
                    {
                        Thread thread = new Thread(new ThreadStart(conv.ConvertVideoToWebM));
                        thread.Start();
                    }
                    else if (video.VideoPath.IndexOf("webm") > 0)
                    {
                        Thread thread = new Thread(new ThreadStart(conv.ConvertVideoToMp4));
                        thread.Start();
                    }
                    string videoFull = video.VideoPath.Split('/')[3];
                    string videoName = videoFull.Split('.')[0];
                    string imageName = "/UploadStore/Videos/" + videoName + ".jpg";
                    video.ImagePath = imageName;
                }
                //  }
                //

                video.URLName = FX.Utils.Common.TextHelper.ToUrlFriendly(video.NameVNI);
                videoSrv.Update(video);
                videoSrv.CommitChanges();
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Edit : " + video.Id, "Edit Video Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                Messages.AddFlashMessage("Cập nhật thành công.");
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Video - Edit : " + video.Id, "Edit Video Error " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                IVideoTypeService videoCateSrv = IoC.Resolve <IVideoTypeService>();
                VideoModels       model        = new VideoModels();
                model.Video      = video;
                model.VideoTypes = videoCateSrv.Query.Where(p => p.Active).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList();
                return(View("Edit", model));
            }
        }