public ActionResult Create()
 {
     ViewBag.Message = Session["msg"];
     ViewBag.Error   = Session["err"];
     Session["err"]  = "";
     Session["msg"]  = "";
     ViewBag.UserID  = new SelectList(db.Users, "UserID", "Email");
     learnersmate.Models.Video video = new learnersmate.Models.Video();
     video.UserID    = Convert.ToInt16(Session["UserID"].ToString());
     video.VideoPath = "/";
     video.Dou       = DateTime.Now;
     return(View(video));
 }
 // GET: Videos/Details/5
 public ActionResult Details(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     learnersmate.Models.Video video = db.Videos.Find(id);
     if (video == null)
     {
         return(HttpNotFound());
     }
     return(View(video));
 }
 public ActionResult Edit(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     learnersmate.Models.Video video = db.Videos.Find(id);
     if (video == null)
     {
         return(HttpNotFound());
     }
     ViewBag.UserID = new SelectList(db.Users, "UserID", "Email", video.UserID);
     return(View(video));
 }
        public ActionResult DeleteConfirm(int id)
        {
            Session["err"] = "Error, Can't Delete, Please check Dependency Data";
            Session["msg"] = "";
            try
            {
                learnersmate.Models.Video video = db.Videos.Find(id);
                db.Videos.Remove(video);
                db.SaveChanges();

                Session["err"] = "";
                Session["msg"] = "Deleted Successfully";
            }
            catch { }
            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "VideoID,Name,Description,VideoPath,FileExt,UserID,Dou")] learnersmate.Models.Video video, HttpPostedFileBase uploadvideo, string newlogo, bool IsYoutube)
        {
            errordata data = new errordata();

            data.type      = "error";
            Session["err"] = "Error, Please Check Input Fields";
            Session["msg"] = "";
            if (newlogo == "")
            {
                Session["err"] = "Video required";
                data.message   = Session["err"].ToString();
                return(Json(data, JsonRequestBehavior.AllowGet));
            }
            else
            {
                if (newlogo != "")
                {
                    video.VideoPath = newlogo;
                    var extention = Path.GetExtension(newlogo);
                    video.FileExt = extention;
                }
                db.Videos.Add(video);
                db.SaveChanges();

                if (IsYoutube)
                {
                    try
                    {
                        //////ref https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=webbased-document-management
                        ///https://console.developers.google.com/apis/credentials?project=webbased-document-management
                        ///https://www.slickremix.com/docs/get-api-key-for-youtube/
                        YouTubeRequestSettings settings;
                        YouTubeRequest         request;
                        string devkey   = ConfigurationManager.AppSettings.Get("youtubedevkey");
                        string username = ConfigurationManager.AppSettings.Get("youtubeusername");
                        string password = ConfigurationManager.AppSettings.Get("youtubepassword");

                        string filepath = Server.MapPath("/" + newlogo.PadLeft(1).Replace("/", "\\"));
                        settings = new YouTubeRequestSettings("education", devkey, username, password)
                        {
                            Timeout = 999999999
                        };
                        request = new YouTubeRequest(settings);
                        Google.YouTube.Video videoyoutube = new Google.YouTube.Video();
                        videoyoutube.Title       = video.Name;
                        videoyoutube.Description = video.Description;
                        videoyoutube.Tags.Add(new MediaCategory("Education", YouTubeNameTable.CategorySchema));
                        videoyoutube.Keywords    = "Education";
                        videoyoutube.Private     = false;
                        videoyoutube.MediaSource = new MediaFileSource(filepath, "video/flv");
                        Google.YouTube.Video createdVideo = request.Upload(videoyoutube); //In that createdVideo you will get uploaded video ID.

                        video.YoutubePath     = createdVideo.VideoId;
                        db.Entry(video).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    catch (Exception exception)

                    {
                        Session["msg"] = "Cant upload youtube, Please check youtube api settings" + exception.Message;
                    }
                }

                Session["err"]  = "";
                Session["msg"] += "Created Successfully";
            }



            data.message = "/Video/Index";
            data.type    = "success";
            return(Json(data, JsonRequestBehavior.AllowGet));
        }