public ActionResult GetSideVideos() { hypster_tv_DAL.videoClipManager videoManager = new hypster_tv_DAL.videoClipManager(); List <hypster_tv_DAL.videoClip> videos_list = videoManager.getTopRatedVideos(); List <hypster_tv_DAL.videoClip> news_list_Display = new List <hypster_tv_DAL.videoClip>(); int maxPostsNum = 3; // WILL NEED TO MOVE TO CONFIG if (videos_list.Count > maxPostsNum) { Random randomGen = new Random(); do { int next_article = randomGen.Next(0, videos_list.Count); hypster_tv_DAL.videoClip item = new hypster_tv_DAL.videoClip(); item = videos_list[next_article]; if (!news_list_Display.Contains(item)) { news_list_Display.Add(item); } } while (news_list_Display.Count < maxPostsNum); } return(View(news_list_Display)); }
public ActionResult Index(hypster_tv_DAL.videoClip clipToAdd, HttpPostedFileBase file) { string file_GUID = ""; if (file != null && file.ContentLength > 0) { if (clipToAdd.Name != null && clipToAdd.Name != "") { file_GUID = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 23); var fileName = System.IO.Path.GetFileName(file.FileName); var extension = System.IO.Path.GetExtension(file.FileName); var path = System.IO.Path.Combine(Server.MapPath("~/uploads_pending"), file_GUID + extension); file.SaveAs(path); clipToAdd.Guid = file_GUID; clipToAdd.UploadDate = DateTime.Now; clipToAdd.Duration = 0; clipToAdd.UploadedByName = User.Identity.Name; clipToAdd.Status = -1; //status (-1) - is pending need to be reviwed to have proper video format hypster_tv_DAL.Hypster_Entities hyDB = new hypster_tv_DAL.Hypster_Entities(); hyDB.AddTovideoClips(clipToAdd); hyDB.SaveChanges(); //return RedirectToAction("Index", "Home"); return(RedirectToAction("UploadConfirmation", "upload")); } else { ModelState.AddModelError("", "Please enter video name"); } } else { ModelState.AddModelError("", "Please select video"); } return(View()); }
public ActionResult Edit(HttpPostedFileBase file, hypster_tv_DAL.videoClip p_clip) { if (Session["Roles"] != null && Session["Roles"].Equals("Admin")) { hypster_tv_DAL.videoClipManager_Admin videoManager = new hypster_tv_DAL.videoClipManager_Admin(); bool isEditingAllowed = true; // //check existing clip before editing //------------------------------------------------------------------------------------------------------------------------------- hypster_tv_DAL.videoClip checkClip = new hypster_tv_DAL.videoClip(); checkClip = videoManager.getVideoByGUID(p_clip.Guid); // if old status was pending and now moving to another status need to move video file from pending directory if (checkClip.Status == -1 && p_clip.Status != -1) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(System.Configuration.ConfigurationManager.AppSettings["videoClipsPending_Path"] + "\\" + p_clip.Guid + ".flv"); if (fileInfo.Exists) { fileInfo.MoveTo(System.Configuration.ConfigurationManager.AppSettings["videoClipsStorage_Path"] + "\\" + p_clip.Guid + ".flv"); } else { isEditingAllowed = false; //do not allow editing since it PENDING video with not supported video encoding } } //------------------------------------------------------------------------------------------------------------------------------- // //editing //------------------------------------------------------------------------------------------------------------------------------- if (isEditingAllowed) { if (file != null && file.ContentLength > 0) { var extension = ".png"; //System.IO.Path.GetExtension(file.FileName); var path = System.IO.Path.Combine(Server.MapPath("~/uploads"), "new_video_cover" + extension); file.SaveAs(path); string image_guid = p_clip.Guid; // // resize image int video_thumb_width = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["videoThumbnail_Width"]); int video_thumb_height = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["videoThumbnail_Height"]); hypster_tv_DAL.Image_Resize_Manager image_resizer = new hypster_tv_DAL.Image_Resize_Manager(); image_resizer.Resize_Image(path, video_thumb_width, video_thumb_height, System.Drawing.Imaging.ImageFormat.Png); System.IO.FileInfo file_slide = new System.IO.FileInfo(Server.MapPath("~/uploads") + "\\" + "new_video_cover" + extension); file_slide.CopyTo(System.Configuration.ConfigurationManager.AppSettings["videoCoversStorage_Path"] + "\\" + image_guid + file_slide.Extension, true); //delete file System.IO.FileInfo del_file = new System.IO.FileInfo(Server.MapPath("~/uploads") + "\\" + "new_video_cover" + extension); del_file.Delete(); } //edit video videoManager.EditVideo(p_clip); } //------------------------------------------------------------------------------------------------------------------------------- return(RedirectToAction(p_clip.Guid)); } else { return(RedirectPermanent("/home/")); } }