Exemple #1
0
        public ActionResult Delete(int id)
        {
            try
            {
                IVideoTypeService typeSrv  = IoC.Resolve <IVideoTypeService>();
                IVideosService    videoSrv = IoC.Resolve <IVideosService>();
                int c = videoSrv.Query.Where(p => p.VideoTypeID == id).Count();
                if (c > 0)
                {
                    Messages.AddErrorFlashMessage("Không được xóa chuyên mục đang sử dụng.");
                    return(RedirectToAction("Index"));
                }
                VideoType type = typeSrv.Getbykey(id);
                typeSrv.Delete(type);
                typeSrv.CommitChanges();
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "VideoType - Delete : " + id, "Delete VideoType 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, "VideoType - Delete : " + id, "Delete VideoType 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"));
        }
Exemple #2
0
        public ActionResult Create(VideoType type)
        {
            try
            {
                IVideoTypeService typeSrv = IoC.Resolve <IVideoTypeService>();
                var c = typeSrv.Query.Where(p => p.NameVNI == type.NameVNI || p.NameENG == type.NameENG).Count();
                if (c > 0)
                {
                    Messages.AddErrorMessage("Tiêu đề tin tức đã tồn tại");
                    VideoTypeModels model = new VideoTypeModels();
                    model.ArtVideoType = type;
                    return(View(model));
                }
                type.UrlName   = FX.Utils.Common.TextHelper.ToUrlFriendly(type.NameVNI);
                type.CreatedBy = HttpContext.User.Identity.Name;
                typeSrv.CreateNew(type);
                typeSrv.CommitChanges();
                Messages.AddFlashMessage("Thêm mới thành công.");
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "VideoType - Create", "Create VideoType Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "VideoType - Create", "Create VideoType 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.");
                VideoTypeModels model = new VideoTypeModels();
                model.ArtVideoType = type;
                return(View(model));
            }
        }
Exemple #3
0
        public ActionResult Index(VideoIndexModel model, int?page)
        {
            int               defautPagesize   = 10;
            int               total            = 0;
            int               currentPageIndex = page.HasValue ? page.Value - 1 : 0;
            IVideosService    videoSrv         = IoC.Resolve <IVideosService>();
            IVideoTypeService videotypeSrv     = IoC.Resolve <IVideoTypeService>();

            model.VideoTypes = videotypeSrv.Query.OrderBy(p => p.NameVNI).OrderBy(p => p.NameENG).ToList();
            string         kw       = String.IsNullOrWhiteSpace(model.Keyword) ? null : model.Keyword.Trim();
            IList <Videos> list     = new List <Videos>();
            string         username = HttpContext.User.Identity.Name;

            model.TypeID = string.IsNullOrWhiteSpace(model.TypeID) ? "0" : model.TypeID;
            int cID = 0;

            int.TryParse(model.TypeID, out cID);
            if (HttpContext.User.IsInRole("Root"))
            {
                list = videoSrv.GetBySearch(kw, cID, currentPageIndex, defautPagesize, out total);
            }
            else
            {
                list = videoSrv.GetBySearch(kw, cID, username, currentPageIndex, defautPagesize, out total);
            }

            model.Videos = new PagedList <Videos>(list, currentPageIndex, defautPagesize, total);
            return(View(model));
        }
Exemple #4
0
        public ActionResult Edit(int id)
        {
            IVideoTypeService artTypeSrv = IoC.Resolve <IVideoTypeService>();
            VideoTypeModels   model      = new VideoTypeModels();

            model.ArtVideoType = artTypeSrv.Getbykey(id);
            return(View(model));
        }
Exemple #5
0
        public ActionResult Create()
        {
            IVideoTypeService artTypeSrv = IoC.Resolve <IVideoTypeService>();
            VideoTypeModels   model      = new VideoTypeModels();

            model.ArtVideoType        = new VideoType();
            model.ArtVideoType.Active = true;
            return(View(model));
        }
Exemple #6
0
        public ActionResult Create()
        {
            IVideoTypeService videoTypeSrv = IoC.Resolve <IVideoTypeService>();
            VideoModels       model        = new VideoModels();

            model.Video        = new Videos();
            model.Video.Active = true;
            model.VideoTypes   = videoTypeSrv.Query.Where(p => p.Active).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList();
            return(View(model));
        }
Exemple #7
0
        public ActionResult Edit(int id)
        {
            IVideosService    videoSrv     = IoC.Resolve <IVideosService>();
            IVideoTypeService videoTypeSrv = IoC.Resolve <IVideoTypeService>();
            VideoModels       model        = new VideoModels();

            model.Video      = videoSrv.Getbykey(id);
            model.VideoTypes = videoTypeSrv.Query.Where(p => p.Active).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList();
            return(View(model));
        }
Exemple #8
0
        public ActionResult Index(VideoTypeIndexModel model, int?page, int?PageSize)
        {
            int defautPagesize           = PageSize.HasValue ? PageSize.Value : 10;
            int total                    = 0;
            int currentPageIndex         = page.HasValue ? page.Value - 1 : 0;
            IVideoTypeService artTypeSrv = IoC.Resolve <IVideoTypeService>();
            string            kw         = String.IsNullOrWhiteSpace(model.Keyword) ? null : model.Keyword.Trim();
            var list = artTypeSrv.GetByFilter(kw, currentPageIndex, defautPagesize, out total);

            model.VideoTypes = new PagedList <VideoType>(list, currentPageIndex, defautPagesize, total);
            return(View(model));
        }
Exemple #9
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));
            }
        }
Exemple #10
0
        public ActionResult Update(int id)
        {
            IVideoTypeService TypeSrv = IoC.Resolve <IVideoTypeService>();
            VideoType         type    = TypeSrv.Getbykey(id);

            try
            {
                TryUpdateModel <VideoType>(type);
                var c = TypeSrv.Query.Where(p => (p.Id != id) && (p.NameVNI == type.NameVNI || p.NameENG == type.NameENG)).Count();
                if (c > 0)
                {
                    Messages.AddErrorMessage("Tiêu đề tin tức đã tồn tại");
                    VideoTypeModels model = new VideoTypeModels();
                    model.ArtVideoType = type;

                    return(View("Edit", model));
                }
                type.UrlName      = FX.Utils.Common.TextHelper.ToUrlFriendly(type.NameVNI);
                type.ModifiedBy   = HttpContext.User.Identity.Name;
                type.ModifiedDate = DateTime.Now;
                TypeSrv.Update(type);
                TypeSrv.CommitChanges();
                Messages.AddFlashMessage("Cập nhật thành công.");
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "VideoType - Update : " + id, "Update VideoType Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "VideoType - Update : " + id, "Update VideoType 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.");

                VideoTypeModels model = new VideoTypeModels();
                model.ArtVideoType = type;

                return(View("Edit", model));
            }
        }
Exemple #11
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));
            }
        }