Esempio n. 1
0
        public ActionResult Create(HttpPostedFileBase profileFile, VideoCategory videocategory)
        {
            videocategory.UniqueTitle = VITV.Web.Helpers.UrlHelper.URLFriendly(videocategory.Name);
            if (profileFile != null && profileFile.ContentLength > 0)
            {
                string fileName      = Convert.ToInt32((DateTime.Now - new DateTime(2010, 01, 01)).TotalSeconds) + "_" + profileFile.FileName;
                string mFileName     = "Mobile_" + fileName;
                string currentDomain = System.Configuration.ConfigurationManager.AppSettings["CurrentDomain"];
                string folder        = "UploadedImages/VideoCategory";
                string filePath      = System.Configuration.ConfigurationManager.AppSettings[currentDomain] + @"\" + folder + @"\" + fileName;
                string mFilePath     = System.Configuration.ConfigurationManager.AppSettings[currentDomain] + @"\" + folder + @"\" + mFileName;

                using (new Impersonator("uploaduser", "", "Upload@@123"))
                {
                    profileFile.SaveAs(filePath);
                    ImageHelper.ScaleBySize(filePath, mFilePath, 250);
                }
                videocategory.ProfilePhoto       = currentDomain + "/" + folder + "/" + fileName;
                videocategory.MobileProfilePhoto = currentDomain + "/" + folder + "/" + mFileName;
            }

            ModelState.Clear();
            TryValidateModel(videocategory);

            if (ModelState.IsValid)
            {
                if (videocategory.GroupId != null)
                {
                    videocategory.Name2 = videocategory.Name;
                }

                //if (videocategory.CategoryIntroId == null || videocategory.CategoryIntroId == 0)
                //    videocategory.CategoryIntroId = null;

                _videocategoryRepository.InsertOrUpdate(videocategory);
                _videocategoryRepository.Save();
                //return RedirectToAction("Details", "VideoCatGroups", new { id = videocategory.GroupId });
                return(RedirectToAction("Index", "VideoCatGroups"));
            }

            ViewBag.PossibleGroups = _catGroupRepository.All.ToList();
            ViewBag.videocattypes  = _catTypeRepository.All.ToList();
            ViewBag.catIntro       = _catIntroRepository.All.ToList();
            ViewBag.pageGroups     = _pageGroupRepository.All.OrderBy(pg => pg.Order).ToList();
            return(View(videocategory));
        }
        public ActionResult ChangeNew(int id, bool deleteVideo)
        {
            ProgramScheduleDetail programScheduleDetail = _scheduleDetailRepository.Find(id);


            if (deleteVideo == true && programScheduleDetail.VideoId.HasValue)
            {
                //Xóa video
                var videoId = programScheduleDetail.VideoId.Value;

                var video = _videoRepository.Find(videoId);
                video.ScheduleDetails.ForEach(sch => sch.VideoId = null);
                _videoCategoryRepository.Save();

                //Xóa file
                using (new Impersonator("uploaduser", "", "Upload@@123"))
                {
                    string thumbnailPath = VITV.Web.Helpers.UrlHelper.GetPhysicalPath(this, video.Thumbnail);
                    if (System.IO.File.Exists(thumbnailPath))
                    {
                        System.IO.File.Delete(thumbnailPath);
                    }

                    string videoPath = VITV.Web.Helpers.UrlHelper.GetPhysicalPath(this, video.Url);

                    if (System.IO.File.Exists(videoPath))
                    {
                        System.IO.File.Delete(videoPath);
                    }
                }
                _videoRepository.Delete(videoId, User.Identity.Name, "Thay đổi phát mới/phát lại");
                _videoRepository.Save();
            }

            programScheduleDetail.IsNew   = !programScheduleDetail.IsNew;
            programScheduleDetail.VideoId = null;
            _videoCategoryRepository.Save();
            var url = programScheduleDetail.IsNew ? Url.Action("Create", "Video", new { scheduleDetailId = programScheduleDetail.Id })
                : Url.Action("UpdateVideoLink", "ProgramScheduleDetails", new { id = programScheduleDetail.Id });

            return(Json(new { success = true, isnew = programScheduleDetail.IsNew, url = url }));
        }