示例#1
0
        public JsonResult FinishOrderByUpImg(IFormFile file)
        {
            string webRootPath = _hostingEnvironment.WebRootPath;
            string fileExt     = file.FileName.Substring(file.FileName.LastIndexOf('.')); //文件扩展名
            string oid         = HttpContext.Session.GetString("VOID");
            string newFileName = oid + fileExt;                                           //随机生成新的文件名
            var    filePath    = webRootPath + "/Content/image/" + newFileName;           //上传文件的完整目录

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                file.CopyTo(stream);
                stream.Flush();
            }
            filePath = "/Content/image/" + newFileName;
            string msg;
            string userId = HttpContext.Session.GetString("UserId");

            if (userId == null)
            {
                msg = "未登录!或登录已失效!";
                return(Json(msg));
            }
            _orderManageService.FinishOrder(oid, filePath, userId, out msg);
            HttpContext.Session.Remove("VOID");
            return(Json(new
            {
                Result = true,
                Data = filePath
            }));
        }