public MtCategory[] GetPostCategories(string postid, string userName, string password)
        {
            ValidateUser(userName, password, Blog.AllowServiceAccess);

            int postId = Int32.Parse(postid, CultureInfo.InvariantCulture);
            ICollection <Link> postCategories = Repository.GetLinkCollectionByPostId(postId);
            var categories = new MtCategory[postCategories.Count];

            if (postCategories.Count > 0)
            {
                // REFACTOR: Might prefer seeing a dictionary come back straight from the provider.
                // for now we'll build our own catid->catTitle lookup--we need it below bc collection
                // from post is going to be null for title.
                ICollection <LinkCategory> cats = Repository.GetCategories(CategoryType.PostCollection, false);
                var catLookup = new Hashtable(cats.Count);
                foreach (LinkCategory currentCat in cats)
                {
                    catLookup.Add(currentCat.Id, currentCat.Title);
                }

                int i = 0;
                foreach (Link link in postCategories)
                {
                    var category = new MtCategory(link.CategoryId.ToString(CultureInfo.InvariantCulture),
                                                  (string)catLookup[link.CategoryId]);

                    categories[i] = category;
                    i++;
                }
            }

            return(categories);
        }
Example #2
0
        public MtCategory[] GetCategoryList(string blogid, string username, string password)
        {
            ValidateUser(username, password, Blog.AllowServiceAccess);

            ICollection<LinkCategory> lcc = Repository.GetCategories(CategoryType.PostCollection, false);
            if (lcc == null)
            {
                throw new XmlRpcFaultException(0, "No categories exist");
            }

            var categories = new MtCategory[lcc.Count];
            int i = 0;
            foreach (LinkCategory linkCategory in lcc)
            {
                var category = new MtCategory(linkCategory.Id.ToString(CultureInfo.InvariantCulture),
                                               linkCategory.Title);
                categories[i] = category;
                i++;
            }
            return categories;
        }
        public MtCategory[] MtGetPostCategories(string postid, string username, string password)
        {
            this.ValidateUser(username, password);

            PostDto item = this.postService.GetPostByKey(postid.ToInt32());

            IList <CategoryDto> categories = this.categoryService.GetCategories();

            MtCategory[] cats = new MtCategory[item.Categories.Length];
            for (int i = 0; i < item.Categories.Length; i++)
            {
                CategoryDto cat = categories.Single(c => c.Name.ToLowerInvariant() == item.Categories[i]);
                cats[i] = new MtCategory
                {
                    categoryId   = cat.Id.ToString(CultureInfo.InvariantCulture),
                    categoryName = cat.Name,

                    // todo: fill up the 'is primary field", maybe this must be true for the first category only
                    isPrimary = (i == 0)
                };
            }

            return(cats);
        }
Example #4
0
        public bool SetPostCategories(string postid, string username, string password,
            MtCategory[] categories)
        {
            //ValidateUser(username, password, Config.CurrentBlog.AllowServiceAccess);

            //if (categories != null && categories.Length > 0)
            //{
            //    int postID = Int32.Parse(postid);

            //    ArrayList al = new ArrayList();


            //    for (int i = 0; i < categories.Length; i++)
            //    {
            //        al.Add(Int32.Parse(categories[i].categoryId));
            //    }

            //    if (al.Count > 0)
            //    {
            //        Entries.SetEntryCategoryList(postID, (int[])al.ToArray(typeof(int)));
            //    }
            //}

            return true;
        }
Example #5
0
        public MtCategory[] GetPostCategories(string postid, string username, string password)
        {
            ValidateUser(username, password, Config.CurrentBlog.AllowServiceAccess);

            int postID = Int32.Parse(postid);
            ICollection<Link> postCategories = Links.GetLinkCollectionByPostID(postID);
            MtCategory[] categories = new MtCategory[postCategories.Count];
            if (postCategories.Count > 0)
            {
                // REFACTOR: Might prefer seeing a dictionary come back straight from the provider.
                // for now we'll build our own catid->catTitle lookup--we need it below bc collection
                // from post is going to be null for title.
                ICollection<LinkCategory> cats = Links.GetCategories(CategoryType.PostCollection, ActiveFilter.None);
                Hashtable catLookup = new Hashtable(cats.Count);
                foreach (LinkCategory currentCat in cats)
                    catLookup.Add(currentCat.Id, currentCat.Title);

                int i = 0;
                foreach(Link link in postCategories)
                {
                    MtCategory _category = new MtCategory(link.CategoryID.ToString(CultureInfo.InvariantCulture), (string)catLookup[link.CategoryID]);

                    categories[i] = _category;
                    i++;
                }
            }

            return categories;
        }
Example #6
0
        public MtCategory[] GetCategoryList(string blogid, string username, string password)
        {
            ValidateUser(username,password,Config.CurrentBlog.AllowServiceAccess);

            ICollection<LinkCategory> lcc = Links.GetCategories(CategoryType.PostCollection, ActiveFilter.None);
            if(lcc == null)
            {
                throw new XmlRpcFaultException(0, "No categories exist");
            }

            MtCategory[] categories = new MtCategory[lcc.Count];
            int i = 0;
            foreach(LinkCategory linkCategory in lcc)
            {
                MtCategory _category = new MtCategory(linkCategory.Id.ToString(CultureInfo.InvariantCulture), linkCategory.Title);
                categories[i] = _category;
                i++;
            }
            return categories;
        }
Example #7
0
        public bool SetPostCategories(string postid, string username, string password,
            MtCategory[] categories)
        {
            ValidateUser(username, password, Blog.AllowServiceAccess);

            if(categories != null && categories.Length > 0)
            {
                int postId = Int32.Parse(postid, CultureInfo.InvariantCulture);

                IEnumerable<int> categoryIds = from category in categories
                                               select int.Parse(category.categoryId, CultureInfo.InvariantCulture);

                if(categoryIds.Any())
                {
                    Repository.SetEntryCategoryList(postId, categoryIds);
                }
            }

            return true;
        }