Esempio n. 1
0
        /// <summary>
        /// Upload files of the vcr Resource.
        /// </summary>
        /// <param name="vid"></param>
        /// <returns></returns>
        public JsonResult VcrResource(string vid)
        {
            string             error = string.Empty;
            HttpPostedFileBase file  = Request.Files["resource"];

            if (file == null)
            {
                return(Json(new { error = "上传失败" }, JsonRequestBehavior.AllowGet));
            }

            if (string.IsNullOrEmpty(vid))
            {
                return(Json(new { error = "没有ID参数" }, JsonRequestBehavior.AllowGet));
            }

            string[] pth      = new string[1];
            string   userfile = GetFilePath(FileType.TxtFile, false);

            if (userfile != null)
            {
                string part2     = DateTime.Now.ToFileTime() + "_" + file.FileName;
                string p         = Path.Combine(Server.MapPath(userfile), part2);
                string returnPth = userfile + "/" + part2;

                try
                {
                    file.SaveAs(p);
                    pth[0] = returnPth;

                    //save the model
                    IVcrFile vcrFilesSv = new VcrFilesSv(vid);

                    string fileId = Guid.NewGuid().ToString("n");
                    vcrFilesSv.Add(new VcrFile
                    {
                        Id       = fileId,
                        MakeDay  = DateTime.Now,
                        Maker    = MyUserId,
                        Path     = returnPth,
                        VcrId    = vid,
                        Name     = file.FileName,
                        FileOk   = true,
                        FileSize = file.ContentLength
                    });
                }
                catch (Exception ex)
                {
                    error = ex.ToString();
                    return(Json(new { error }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { initialPreview = pth }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { error = "遇到错误...", initialPreview = "<p>失败,请重试...</p>", }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ActionResult Del(string id)
        {
            int r = new VcrFilesSv().DelFile(id);

            return(Json(new { i = r }, JsonRequestBehavior.AllowGet));
        }