Example #1
0
        public ActionResult PostVideo(HttpPostedFileBase file, Models.Video video, string tags)
        {
            Models.User user = new Models.User();

            user.username      = Session["userId"].ToString().Split('-')[1];
            user.discriminator = int.Parse(Session["userId"].ToString().Split('-')[0]);


            foreach (string tagtext in tags.Split(' ').ToList())
            {
                Models.Tag tag = new Tag();
                tag.text = tagtext;
                video.tags.Add(tag);
            }

            //video.title = Request.QueryString.Get("title");
            //video.description = Request.QueryString.Get("description");
            video.thumbnail = "defaultthumbnail.png";


            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = Path.Combine(Server.MapPath("../videos"),
                                               Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                    ViewBag.Message = "File uploaded successfully";
                    video.videoFile = file.FileName;
                }
                catch (Exception ex)
                {
                    ViewBag.Message        = "ERROR:" + ex.Message.ToString();
                    video.VideoUploadError = "ERROR:" + ex.Message.ToString();
                    return(new ContentResult()
                    {
                        Content = "ERROR:" + ex.Message.ToString()
                    });
                }
            }
            else
            {
                ViewBag.Message        = "You have not specified a file.";
                video.VideoUploadError = "You have not specified a file.";
                return(new ContentResult()
                {
                    Content = "You have not specified a file."
                });
            }


            VideoBll videoBll = new VideoBll();

            video = videoBll.CreateVideo(user, video);
            return(RedirectToAction("VideoPage", "Home", new { id = video.id }));

            return(new ContentResult()
            {
                Content = "Video posted"
            });
        }