Example #1
0
 public ActionResult Create(ResponseVideo ResponseVideo)
 {
     if (ModelState.IsValid)
     {
         ResponseVideoRepository.Add(ResponseVideo);
         ResponseVideoRepository.Context.Commit();
         return RedirectToAction("Index");
     }
     return View(ResponseVideo);
 }
Example #2
0
        public ActionResult UpLoadVideo()
        {
            HttpPostedFileBase imgFile = Request.Files[0];
            if (imgFile != null)
            {
                if (User.Identity.Name != "")
                {
                    //获得上传图片的名字
                    string strPath = imgFile.FileName;
                    string type = strPath.Substring(strPath.LastIndexOf(".") + 1).ToLower();
                    if (ValidateVideo(type))
                    {
                        //获取上传用户id
                        int userid = WebSecurity.GetUserId(User.Identity.Name);
                        ResponseVideo ResponseVideo = new ResponseVideo();
                        ResponseVideo.AddTime = DateTime.Now;
                        ResponseVideo.UserId = userid;
                        ResponseVideo.VideoName = imgFile.FileName.Replace("." + type, "");
                        string uppath = System.Web.HttpContext.Current.Server.MapPath("~/images/ResponseVideo/" + userid.ToString());
                        ResponseVideo.VideoUrl = "/images/ResponseVideo/" + userid.ToString() + "/" + imgFile.FileName;
                        if (!Directory.Exists(uppath))
                        {
                            Directory.CreateDirectory(uppath);
                        }

                        if (imgFile.ContentLength < 1024 * 1024 * 20)
                        {
                            if (ResponseVideoRepository.Find(Specification<ResponseVideo>.Eval(o => o.VideoName == strPath.Replace("." + type, "") && o.UserId == userid)) == null)
                            {
                                imgFile.SaveAs(uppath + "\\" + imgFile.FileName);
                                if (ModelState.IsValid)
                                {
                                    ResponseVideoRepository.Add(ResponseVideo);
                                    ResponseVideoRepository.Context.Commit();
                                    return Redirect("/ResponseVideo/Index");
                                }
                            }
                            else
                            {
                                TempData["ErrorMessage"] = "语音名称已经存在";
                            }
                        }
                        else
                        {
                            TempData["ErrorMessage"] = "语音大小小于20M";
                        }
                    }
                    else
                    {
                        TempData["ErrorMessage"] = "类型格式错误";
                    }
                }
                else
                {
                }
            }
            else
            {
                TempData["ErrorMessage"] = "上传语音不能为空";
            }
            return Redirect("/ResponseVideo/Create");
        }