コード例 #1
0
ファイル: NB_FileController.cs プロジェクト: SLSoft/GGZBTQPT
        public ActionResult Create(T_NB_File t_nb_file, int UpType,int parentId)
        {
            if (Request.IsAjaxRequest())
            {
                if (ModelState.IsValid)
                {
                    t_nb_file.CreatedTime = DateTime.Now;
                    t_nb_file.UpdateTime = DateTime.Now;
                    t_nb_file.SendUserId = CurrentUser().ID;
                    t_nb_file.ParentID = parentId;

                    if (Session["NbFile"] != null && Session["NbFile"].ToString() != "")
                    {
                        Stream stream = (Stream)Session["NbFile"];
                        //存入文件
                        if (stream.Length > 0)
                        {
                            if (UpType == 1)
                            {
                                t_nb_file.File = new byte[stream.Length];
                                stream.Read(t_nb_file.File, 0, t_nb_file.File.Length);
                            }
                            else
                            {
                                if (parentId == 0)
                                {
                                    return ReturnJson(false, "请选择有效的文件夹", "", "", false, "");
                                }
                                t_nb_file.FileUrl = UpLoadFile(stream);
                                t_nb_file.IsShare = true;
                            }

                            t_nb_file.FileName = Session["FileName"].ToString();
                        }
                    }
                    else
                    {
                        return ReturnJson(false, "请选择上传文件", "", "", false, "");
                    }

                    db.T_NB_File.Add(t_nb_file);

                    int result = db.SaveChanges();
                    if (result > 0)
                    {
                        return ReturnJson(true, "操作成功", "", "", true, "");
                    }
                    else
                    {
                        return ReturnJson(false, "操作失败", "", "", false, "");
                    }
                }
            }
            return Json(new { });
        }
コード例 #2
0
ファイル: NB_FileController.cs プロジェクト: SLSoft/GGZBTQPT
        public ActionResult FolderCreate(int parentId, FormCollection collection)
        {
            if (Request.IsAjaxRequest())
            {
                if (ModelState.IsValid)
                {
                    T_NB_File t_nb_file = new T_NB_File();
                    t_nb_file.CreatedTime = DateTime.Now;
                    t_nb_file.UpdateTime = DateTime.Now;
                    t_nb_file.SendUserId = CurrentUser().ID;
                    t_nb_file.Title = collection["Title"].ToString();
                    t_nb_file.IsFolder = true;
                    t_nb_file.ParentID = parentId;

                    db.T_NB_File.Add(t_nb_file);

                    int result = db.SaveChanges();
                    if (result > 0)
                    {
                        return ReturnJson(true, "操作成功", "", "", true, "");
                    }
                    else
                    {
                        return ReturnJson(false, "操作失败", "", "", false, "");
                    }
                }
            }
            return Json(new { });
        }