Example #1
0
        public async Task <ActionResult> ImportPage(HttpPostedFileBase __filename, ImportPageModel model)
#endif
        {
            FileUpload upload   = new FileUpload();
            string     tempName = await upload.StoreTempPackageFileAsync(__filename);

            List <string> errorList = new List <string>();

            PageDefinition.ImportInfo info = await PageDefinition.ImportAsync(tempName, errorList);

            await FileSystem.TempFileSystemProvider.DeleteFileAsync(tempName);

            string errs = "";

            if (errorList.Count > 0)
            {
                ScriptBuilder sbErr = new ScriptBuilder();
                sbErr.Append(errorList, LeadingNL: true);
                errs = sbErr.ToString();
            }
            if (info.Success)
            {
                string         msg  = this.__ResStr("imported", "\"{0}\" successfully imported(+nl)", __filename.FileName) + errs;
                UploadResponse resp = new UploadResponse {
                    Result = $"$YetaWF.confirm('{Utility.JserEncode(msg)}', null, function() {{ window.location.assign('{Utility.JserEncode(info.Url)}'); }} );",
                };
                return(new YJsonResult {
                    Data = resp
                });
            }
            else
            {
                // Anything else is a failure
                throw new Error(this.__ResStr("cantImport", "Can't import {0}:(+nl)", __filename.FileName) + errs);
            }
        }