public IHttpActionResult Submit() { try { var request = new AuthenticatedRequest(); var siteId = request.GetPostInt("siteId"); var channelId = request.GetPostInt("channelId"); var importType = request.GetPostString("importType"); var checkedLevel = request.GetPostInt("checkedLevel"); var isOverride = request.GetPostBool("isOverride"); var fileNames = request.GetPostObject <List <string> >("fileNames"); if (!request.IsAdminLoggin || !request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId, ConfigManager.ChannelPermissions.ContentAdd)) { return(Unauthorized()); } var siteInfo = SiteManager.GetSiteInfo(siteId); if (siteInfo == null) { return(BadRequest("无法确定内容对应的站点")); } var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId); if (channelInfo == null) { return(BadRequest("无法确定内容对应的栏目")); } var isChecked = checkedLevel >= siteInfo.Additional.CheckContentLevel; if (importType == "zip") { foreach (var fileName in fileNames) { var localFilePath = PathUtils.GetTemporaryFilesPath(fileName); if (!EFileSystemTypeUtils.Equals(EFileSystemType.Zip, PathUtils.GetExtension(localFilePath))) { continue; } var importObject = new ImportObject(siteId, request.AdminName); importObject.ImportContentsByZipFile(channelInfo, localFilePath, isOverride, isChecked, checkedLevel, request.AdminId, 0, SourceManager.Default); } } else if (importType == "csv") { foreach (var fileName in fileNames) { var localFilePath = PathUtils.GetTemporaryFilesPath(fileName); if (!EFileSystemTypeUtils.Equals(EFileSystemType.Csv, PathUtils.GetExtension(localFilePath))) { continue; } var importObject = new ImportObject(siteId, request.AdminName); importObject.ImportContentsByCsvFile(channelInfo, localFilePath, isOverride, isChecked, checkedLevel, request.AdminId, 0, SourceManager.Default); } } else if (importType == "txt") { foreach (var fileName in fileNames) { var localFilePath = PathUtils.GetTemporaryFilesPath(fileName); if (!EFileSystemTypeUtils.Equals(EFileSystemType.Txt, PathUtils.GetExtension(localFilePath))) { continue; } var importObject = new ImportObject(siteId, request.AdminName); importObject.ImportContentsByTxtFile(channelInfo, localFilePath, isOverride, isChecked, checkedLevel, request.AdminId, 0, SourceManager.Default); } } request.AddSiteLog(siteId, channelId, 0, "导入内容", string.Empty); return(Ok(new { Value = true })); } catch (Exception ex) { LogUtils.AddErrorLog(ex); return(InternalServerError(ex)); } }
public override void Submit_OnClick(object sender, EventArgs e) { if (HifFile.PostedFile == null || "" == HifFile.PostedFile.FileName) { return; } var isChecked = false; var checkedLevel = TranslateUtils.ToIntWithNagetive(DdlContentLevel.SelectedValue); if (checkedLevel >= SiteInfo.Additional.CheckContentLevel) { isChecked = true; } try { if (StringUtils.EqualsIgnoreCase(DdlImportType.SelectedValue, ModalExportMessage.ExportTypeContentZip)) { var filePath = HifFile.PostedFile.FileName; if (!EFileSystemTypeUtils.Equals(EFileSystemType.Zip, PathUtils.GetExtension(filePath))) { FailMessage("必须上传后缀为“.zip”的压缩文件"); return; } var localFilePath = PathUtils.GetTemporaryFilesPath(PathUtils.GetFileName(filePath)); HifFile.PostedFile.SaveAs(localFilePath); var importObject = new ImportObject(SiteId, AuthRequest.AdminName); var nodeInfo = ChannelManager.GetChannelInfo(SiteId, _channelId); importObject.ImportContentsByZipFile(nodeInfo, localFilePath, TranslateUtils.ToBool(DdlIsOverride.SelectedValue), TranslateUtils.ToInt(TbImportStart.Text), TranslateUtils.ToInt(TbImportCount.Text), isChecked, checkedLevel); } else if (StringUtils.EqualsIgnoreCase(DdlImportType.SelectedValue, ModalExportMessage.ExportTypeContentAccess)) { var filePath = HifFile.PostedFile.FileName; if (!StringUtils.EqualsIgnoreCase(PathUtils.GetExtension(filePath), ".mdb")) { FailMessage("必须上传后缀为“.mdb”的Access文件"); return; } var localFilePath = PathUtils.GetTemporaryFilesPath(PathUtils.GetFileName(filePath)); HifFile.PostedFile.SaveAs(localFilePath); var importObject = new ImportObject(SiteId, AuthRequest.AdminName); importObject.ImportContentsByAccessFile(_channelId, localFilePath, TranslateUtils.ToBool(DdlIsOverride.SelectedValue), TranslateUtils.ToInt(TbImportStart.Text), TranslateUtils.ToInt(TbImportCount.Text), isChecked, checkedLevel); } else if (StringUtils.EqualsIgnoreCase(DdlImportType.SelectedValue, ModalExportMessage.ExportTypeContentExcel)) { var filePath = HifFile.PostedFile.FileName; if (!StringUtils.EqualsIgnoreCase(PathUtils.GetExtension(filePath), ".csv")) { FailMessage("必须上传后缀为“.csv”的Excel文件"); return; } var localFilePath = PathUtils.GetTemporaryFilesPath(PathUtils.GetFileName(filePath)); HifFile.PostedFile.SaveAs(localFilePath); var importObject = new ImportObject(SiteId, AuthRequest.AdminName); importObject.ImportContentsByCsvFile(_channelId, localFilePath, TranslateUtils.ToBool(DdlIsOverride.SelectedValue), TranslateUtils.ToInt(TbImportStart.Text), TranslateUtils.ToInt(TbImportCount.Text), isChecked, checkedLevel); } else if (StringUtils.EqualsIgnoreCase(DdlImportType.SelectedValue, ModalExportMessage.ExportTypeContentTxtZip)) { var filePath = HifFile.PostedFile.FileName; if (!EFileSystemTypeUtils.Equals(EFileSystemType.Zip, PathUtils.GetExtension(filePath))) { FailMessage("必须上传后缀为“.zip”的压缩文件"); return; } var localFilePath = PathUtils.GetTemporaryFilesPath(PathUtils.GetFileName(filePath)); HifFile.PostedFile.SaveAs(localFilePath); var importObject = new ImportObject(SiteId, AuthRequest.AdminName); importObject.ImportContentsByTxtZipFile(_channelId, localFilePath, TranslateUtils.ToBool(DdlIsOverride.SelectedValue), TranslateUtils.ToInt(TbImportStart.Text), TranslateUtils.ToInt(TbImportCount.Text), isChecked, checkedLevel); } AuthRequest.AddSiteLog(SiteId, _channelId, 0, "导入内容", string.Empty); LayerUtils.Close(Page); } catch (Exception ex) { FailMessage(ex, "导入内容失败!"); } }
public override void Submit_OnClick(object sender, EventArgs e) { if (myFile.PostedFile != null && "" != myFile.PostedFile.FileName) { var isChecked = false; var checkedLevel = TranslateUtils.ToIntWithNagetive(ContentLevel.SelectedValue); if (checkedLevel >= PublishmentSystemInfo.CheckContentLevel) { isChecked = true; } try { if (StringUtils.EqualsIgnoreCase(ImportType.SelectedValue, ModalExportMessage.ExportTypeContentZip)) { var filePath = myFile.PostedFile.FileName; if (!EFileSystemTypeUtils.Equals(EFileSystemType.Zip, PathUtils.GetExtension(filePath))) { FailMessage("必须上传后缀为“.zip”的压缩文件"); return; } var localFilePath = PathUtils.GetTemporaryFilesPath(PathUtils.GetFileName(filePath)); myFile.PostedFile.SaveAs(localFilePath); var importObject = new ImportObject(PublishmentSystemId); var nodeInfo = NodeManager.GetNodeInfo(PublishmentSystemId, _nodeId); importObject.ImportContentsByZipFile(nodeInfo, localFilePath, TranslateUtils.ToBool(IsOverride.SelectedValue), TranslateUtils.ToInt(ImportStart.Text), TranslateUtils.ToInt(ImportCount.Text), isChecked, checkedLevel); } else if (StringUtils.EqualsIgnoreCase(ImportType.SelectedValue, ModalExportMessage.ExportTypeContentAccess)) { var filePath = myFile.PostedFile.FileName; if (!StringUtils.EqualsIgnoreCase(PathUtils.GetExtension(filePath), ".mdb")) { FailMessage("必须上传后缀为“.mdb”的Access文件"); return; } var localFilePath = PathUtils.GetTemporaryFilesPath(PathUtils.GetFileName(filePath)); myFile.PostedFile.SaveAs(localFilePath); var importObject = new ImportObject(PublishmentSystemId); importObject.ImportContentsByAccessFile(_nodeId, localFilePath, TranslateUtils.ToBool(IsOverride.SelectedValue), TranslateUtils.ToInt(ImportStart.Text), TranslateUtils.ToInt(ImportCount.Text), isChecked, checkedLevel); } else if (StringUtils.EqualsIgnoreCase(ImportType.SelectedValue, ModalExportMessage.ExportTypeContentExcel)) { var filePath = myFile.PostedFile.FileName; if (!StringUtils.EqualsIgnoreCase(PathUtils.GetExtension(filePath), ".csv")) { FailMessage("必须上传后缀为“.csv”的Excel文件"); return; } var localFilePath = PathUtils.GetTemporaryFilesPath(PathUtils.GetFileName(filePath)); myFile.PostedFile.SaveAs(localFilePath); var importObject = new ImportObject(PublishmentSystemId); importObject.ImportContentsByCsvFile(_nodeId, localFilePath, TranslateUtils.ToBool(IsOverride.SelectedValue), TranslateUtils.ToInt(ImportStart.Text), TranslateUtils.ToInt(ImportCount.Text), isChecked, checkedLevel); } else if (StringUtils.EqualsIgnoreCase(ImportType.SelectedValue, ModalExportMessage.ExportTypeContentTxtZip)) { var filePath = myFile.PostedFile.FileName; if (!EFileSystemTypeUtils.Equals(EFileSystemType.Zip, PathUtils.GetExtension(filePath))) { FailMessage("必须上传后缀为“.zip”的压缩文件"); return; } var localFilePath = PathUtils.GetTemporaryFilesPath(PathUtils.GetFileName(filePath)); myFile.PostedFile.SaveAs(localFilePath); var importObject = new ImportObject(PublishmentSystemId); importObject.ImportContentsByTxtZipFile(_nodeId, localFilePath, TranslateUtils.ToBool(IsOverride.SelectedValue), TranslateUtils.ToInt(ImportStart.Text), TranslateUtils.ToInt(ImportCount.Text), isChecked, checkedLevel); } Body.AddSiteLog(PublishmentSystemId, _nodeId, 0, "导入内容", string.Empty); PageUtils.CloseModalPage(Page); } catch (Exception ex) { FailMessage(ex, "导入内容失败!"); } } }