public IHttpActionResult Update(int siteId, int channelId) { try { var request = new AuthenticatedRequest(); var isAuth = request.IsApiAuthenticated && AccessTokenManager.IsScope(request.ApiToken, AccessTokenManager.ScopeChannels) || request.IsAdminLoggin && request.AdminPermissions.HasChannelPermissions(siteId, channelId, ConfigManager.ChannelPermissions.ChannelEdit); if (!isAuth) { return(Unauthorized()); } var siteInfo = SiteManager.GetSiteInfo(siteId); if (siteInfo == null) { return(BadRequest("无法确定内容对应的站点")); } var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId); if (channelInfo == null) { return(BadRequest("无法确定内容对应的栏目")); } channelInfo.Additional.Load(request.GetPostObject <Dictionary <string, object> >()); if (request.IsPostExists(ChannelAttribute.ChannelName)) { channelInfo.ChannelName = request.GetPostString(ChannelAttribute.ChannelName); } if (request.IsPostExists(ChannelAttribute.IndexName)) { var indexName = request.GetPostString(ChannelAttribute.IndexName); if (!channelInfo.IndexName.Equals(indexName) && !string.IsNullOrEmpty(indexName)) { var indexNameList = DataProvider.ChannelDao.GetIndexNameList(siteId); if (indexNameList.IndexOf(indexName) != -1) { return(BadRequest("栏目属性修改失败,栏目索引已存在!")); } } channelInfo.IndexName = indexName; } if (request.IsPostExists(ChannelAttribute.ContentModelPluginId)) { var contentModelPluginId = request.GetPostString(ChannelAttribute.ContentModelPluginId); if (channelInfo.ContentModelPluginId != contentModelPluginId) { channelInfo.ContentModelPluginId = contentModelPluginId; } } if (request.IsPostExists(ChannelAttribute.ContentRelatedPluginIds)) { channelInfo.ContentRelatedPluginIds = request.GetPostString(ChannelAttribute.ContentRelatedPluginIds); } if (request.IsPostExists(ChannelAttribute.FilePath)) { var filePath = request.GetPostString(ChannelAttribute.FilePath); filePath = filePath.Trim(); if (!channelInfo.FilePath.Equals(filePath) && !string.IsNullOrEmpty(filePath)) { if (!DirectoryUtils.IsDirectoryNameCompliant(filePath)) { return(BadRequest("栏目页面路径不符合系统要求!")); } if (PathUtils.IsDirectoryPath(filePath)) { filePath = PageUtils.Combine(filePath, "index.html"); } var filePathList = DataProvider.ChannelDao.GetAllFilePathBySiteId(siteId); if (filePathList.IndexOf(filePath) != -1) { return(BadRequest("栏目修改失败,栏目页面路径已存在!")); } } channelInfo.FilePath = filePath; } if (request.IsPostExists(ChannelAttribute.ChannelFilePathRule)) { var channelFilePathRule = request.GetPostString(ChannelAttribute.ChannelFilePathRule); if (!string.IsNullOrEmpty(channelFilePathRule)) { var filePathRule = channelFilePathRule.Replace("|", string.Empty); if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule)) { return(BadRequest("栏目页面命名规则不符合系统要求!")); } if (PathUtils.IsDirectoryPath(filePathRule)) { return(BadRequest("栏目页面命名规则必须包含生成文件的后缀!")); } } channelInfo.ChannelFilePathRule = channelFilePathRule; } if (request.IsPostExists(ChannelAttribute.ContentFilePathRule)) { var contentFilePathRule = request.GetPostString(ChannelAttribute.ContentFilePathRule); if (!string.IsNullOrEmpty(contentFilePathRule)) { var filePathRule = contentFilePathRule.Replace("|", string.Empty); if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule)) { return(BadRequest("内容页面命名规则不符合系统要求!")); } if (PathUtils.IsDirectoryPath(filePathRule)) { return(BadRequest("内容页面命名规则必须包含生成文件的后缀!")); } } channelInfo.ContentFilePathRule = contentFilePathRule; } if (request.IsPostExists(ChannelAttribute.GroupNameCollection)) { channelInfo.GroupNameCollection = request.GetPostString(ChannelAttribute.GroupNameCollection); } if (request.IsPostExists(ChannelAttribute.ImageUrl)) { channelInfo.ImageUrl = request.GetPostString(ChannelAttribute.ImageUrl); } if (request.IsPostExists(ChannelAttribute.Content)) { channelInfo.Content = request.GetPostString(ChannelAttribute.Content); } if (request.IsPostExists(ChannelAttribute.Keywords)) { channelInfo.Keywords = request.GetPostString(ChannelAttribute.Keywords); } if (request.IsPostExists(ChannelAttribute.Description)) { channelInfo.Description = request.GetPostString(ChannelAttribute.Description); } if (request.IsPostExists(ChannelAttribute.LinkUrl)) { channelInfo.LinkUrl = request.GetPostString(ChannelAttribute.LinkUrl); } if (request.IsPostExists(ChannelAttribute.LinkType)) { channelInfo.LinkType = request.GetPostString(ChannelAttribute.LinkType); } if (request.IsPostExists(ChannelAttribute.ChannelTemplateId)) { channelInfo.ChannelTemplateId = request.GetPostInt(ChannelAttribute.ChannelTemplateId); } if (request.IsPostExists(ChannelAttribute.ContentTemplateId)) { channelInfo.ContentTemplateId = request.GetPostInt(ChannelAttribute.ContentTemplateId); } DataProvider.ChannelDao.Update(channelInfo); return(Ok(new { Value = channelInfo.ToDictionary() })); } catch (Exception ex) { LogUtils.AddErrorLog(ex); return(InternalServerError(ex)); } }