public ActionResult UpdateVideoLink(ProgramScheduleDetail detail)
        {
            if (detail.VideoId != null)
            {
                _scheduleDetailRepository.UpdateVideo(detail.Id, detail.VideoId.Value);
                _scheduleDetailRepository.Save();
            }

            return(RedirectToAction("Management", new { date = detail.DateTime.ToShortDateString() }));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProgramScheduleDetail programScheduleDetail = _scheduleDetailRepository.Find(id.Value);

            return(PartialView(programScheduleDetail));
        }
        public PartialViewResult Insert(ProgramScheduleDetail scheduleDetail, DateTime date)
        {
            scheduleDetail.DateTime = date.Add(scheduleDetail.DateTime.TimeOfDay);
            _scheduleDetailRepository.InsertOrUpdate(scheduleDetail);
            _scheduleDetailRepository.Save();

            var scheduleDetails =
                _scheduleDetailRepository.AllIncluding(s => s.VideoCategory).Where(p => DbFunctions.TruncateTime(p.DateTime) == date).OrderBy(p => p.DateTime).ToList();

            //return new EmptyResult();
            return(PartialView("_ListEdit", scheduleDetails));
        }
Exemplo n.º 4
0
 public void InsertOrUpdate(ProgramScheduleDetail programScheduleDetail)
 {
     if (programScheduleDetail.Id == default(int))
     {
         // New entity
         _context.ProgramScheduleDetails.Add(programScheduleDetail);
     }
     else
     {
         // Existing entity
         _context.Entry(programScheduleDetail).State = EntityState.Modified;
     }
 }
 public ActionResult Edit([Bind(Include = "Id,VideoCategoryId,VideoId,DateTime,Name, IsNew")] ProgramScheduleDetail programScheduleDetail, DateTime date)
 {
     if (ModelState.IsValid)
     {
         programScheduleDetail.DateTime = date.Add(programScheduleDetail.DateTime.TimeOfDay);
         _scheduleDetailRepository.InsertOrUpdate(programScheduleDetail);
         _scheduleDetailRepository.Save();
         return(RedirectToAction("Management", new { date = programScheduleDetail.DateTime.ToShortDateString() }));
     }
     ViewBag.VideoCategoryId = new SelectList(_videoCategoryRepository.GetMany(cat => cat.Children.Count == 0, cat => cat.Name),
                                              "Id",
                                              "Name",
                                              programScheduleDetail.VideoCategoryId);
     return(View(programScheduleDetail));
 }
        public PartialViewResult Insert(DateTime?date)
        {
            if (date == null)
            {
                date = DateTime.Now;
            }
            var model = new ProgramScheduleDetail
            {
                DateTime = date.Value
            };

            ViewBag.VideoCategoryId = new SelectList(_videoCategoryRepository.GetMany(cat => cat.Children.Count == 0, cat => cat.Name),
                                                     "Id",
                                                     "Name");
            return(PartialView("_Insert", model));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProgramScheduleDetail programScheduleDetail = _scheduleDetailRepository.Find(id.Value);

            if (programScheduleDetail == null)
            {
                return(HttpNotFound());
            }
            ViewBag.VideoCategoryId = new SelectList(_videoCategoryRepository.GetMany(cat => cat.Children.Count == 0, cat => cat.Name),
                                                     "Id",
                                                     "Name",
                                                     programScheduleDetail.VideoCategoryId);
            return(View(programScheduleDetail));
        }
        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 }));
        }