public CategoryInfo[] getCategories( string blogid, string username, string password) { if (validateUser(username, password)) { Channel userChannel = new Channel(username); if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "") { // Find the propertytype via the document type ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias); PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias); // check if the datatype uses tags or prevalues CategoryInfo[] returnedCategories = null; interfaces.IUseTags tags = UseTags(categoryType); if (tags != null) { List<interfaces.ITag> alltags = tags.GetAllTags(); if (alltags != null) { returnedCategories = new CategoryInfo[alltags.Count]; int counter = 0; foreach (interfaces.ITag t in alltags) { CategoryInfo ci = new CategoryInfo(); ci.title = t.TagCaption; ci.categoryid = t.Id.ToString(); ci.description = ""; ci.rssUrl = ""; ci.htmlUrl = ""; returnedCategories[counter] = ci; counter++; } } else { returnedCategories = new CategoryInfo[0]; } } else { SortedList categories = PreValues.GetPreValues(categoryType.DataTypeDefinition.Id); returnedCategories = new CategoryInfo[categories.Count]; IDictionaryEnumerator ide = categories.GetEnumerator(); int counter = 0; while (ide.MoveNext()) { PreValue category = (PreValue)ide.Value; CategoryInfo ci = new CategoryInfo(); ci.title = category.Value; ci.categoryid = category.Id.ToString(); ci.description = ""; ci.rssUrl = ""; ci.htmlUrl = ""; returnedCategories[counter] = ci; counter++; } } return returnedCategories; } } throw new ArgumentException("Categories doesn't work for this channel, they might not have been activated. Contact your umbraco administrator."); }
/// <summary> /// 获取栏目 /// </summary> /// <param name="blogid"></param> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> public CategoryInfo[] getCategories(string blogid, string username, string password) { //第一个博客 User user; if ((user = ValidUser(username, password)) != null) { CategoryInfo[] categoryInfos; IList<CategoryDto> categories; //if (user.SiteId > 0) //{ //获取当前管理员的站点 // categories =new List<global::Spc.Models.Category>(cbll.GetCategories(a => a.SiteId == user.SiteId)); //} //else //{ // categories = cbll.GetCategories(); //} categories = new List<CategoryDto>(ServiceCall.Instance.SiteService.GetCategories(this.siteId)); if (categories == null || categories.Count == 0) return null; //赋值栏目数组 categoryInfos = new CategoryInfo[categories.Count]; for (int i = 0; i < categories.Count; i++) { categoryInfos[i] = new CategoryInfo { categoryid = categories[i].Id.ToString(), title = categories[i].Name, description = categories[i].Description ?? String.Empty, htmlUrl = String.Format("/{0}/", categories[i].Tag), rssUrl = String.Format("/rss/{0}/", categories[i].Tag) }; } return categoryInfos; } throw new XmlRpcFaultException(0, "用户密码不正确"); }