コード例 #1
0
ファイル: CategoryService.cs プロジェクト: kissfu/iBlog
        /// <summary>
        /// The add category.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int AddCategory(CategoryEntity entity)
        {
            if (entity != null)
            {
                this.categoryTable.InsertOnSubmit(entity);
                this.Context.SubmitChanges();

                return entity.ID;
            }

            return -1;
        }
コード例 #2
0
ファイル: CategoryService.cs プロジェクト: kissfu/iBlog
        /// <summary>
        /// The get categories by post id.
        /// </summary>
        /// <param name="postID">
        /// The post id.
        /// </param>
        /// <returns>
        /// The <see cref="List{CategoryEntity}"/>.
        /// </returns>
        public List<CategoryEntity> GetCategoriesByPostID(int postID)
        {
            var categoriesEntities = new List<CategoryEntity>();
            List<CategoryEntity> allCategories = this.GetAllCategories();
            List<CategoryMappingEntity> postCategoryMappings =
                this.categoryMappingTable.Where(m => m.PostID == postID).ToList();

            postCategoryMappings.ForEach(
                mapping =>
                    {
                        CategoryEntity category = allCategories.Single(c => c.ID == mapping.CategoryID);
                        var categoryEntity = new CategoryEntity
                                                 {
                                                     ID = mapping.CategoryID,
                                                     Name = category.Name,
                                                     Slug = category.Slug
                                                 };
                        categoriesEntities.Add(categoryEntity);
                    });

            return categoriesEntities;
        }