Esempio n. 1
0
        public ActionResult Create(Post p, HttpPostedFileBase video, string noidung, string mota, HttpPostedFileBase poster)
        {
            PostCategory2Controller.se = null;
            ViewBags();
            if (ModelState.IsValid)
            {
                var    FileName = Path.GetFileName(video.FileName);
                string path     = Path.Combine(Server.MapPath("~/Common/video"), FileName);
                video.SaveAs(path);

                var    Poster = Path.GetFileName(poster.FileName);
                string path2  = Path.Combine(Server.MapPath("~/Common/img"), Poster);
                poster.SaveAs(path2);

                if (WebYoutube.Session.User.Id == 0)
                {
                }
                else
                {
                    if (string.IsNullOrEmpty(p.Title) && string.IsNullOrEmpty(p.Content) && string.IsNullOrEmpty(FileName))
                    {
                    }
                    else
                    {
                        p.Video       = FileName;
                        p.PeopleID    = WebYoutube.Session.User.Id;
                        p.Status      = true;
                        p.CreateDate  = DateTime.Now;
                        p.Content     = noidung;
                        p.Description = mota;
                        p.Poster      = Poster;
                        // add
                        try
                        {
                            dao2.Add(p);
                            //return RedirectToAction("");
                            return(Redirect("~/"));
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError("", ex.ToString());
                        }
                    }
                }
            }
            return(View());
        }