Ejemplo n.º 1
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.º 2
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));
            }
        }