Example #1
0
        private async Task SavePostCategory(CreatePostViewModel createPostViewModel, IPostCategoryServices postCategoryServices, ICategoryServices categoryServices)
        {
            if (createPostViewModel.SelectedCategories?.Count > 0)
            {
                foreach (string category in createPostViewModel.SelectedCategories)
                {
                    Category cat = await categoryServices.GetCategory(new Category { Name = category });

                    PostCategory postCategory = new PostCategory {
                        PostId = createPostViewModel.Post.Id, CategoryId = cat.Id
                    };
                    await postCategoryServices.SavePostCategory(postCategory);
                }
            }
        }
Example #2
0
        private async Task UpdatePostCategory(CreatePostViewModel createPostViewModel, IPostCategoryServices postCategoryServices, ICategoryServices categoryServices)
        {
            //Delete existing PostCategory entries
            await DeleteExistingPostCategoryEntries(createPostViewModel.Post.Id, postCategoryServices);

            //Add new PostCategory entries if there are any entries
            if (createPostViewModel.SelectedCategories != null)
            {
                foreach (string category in createPostViewModel.SelectedCategories)
                {
                    Category cat = await categoryServices.GetCategory(new Category { Name = category });

                    PostCategory postCategory = new PostCategory {
                        PostId = createPostViewModel.Post.Id, CategoryId = cat.Id
                    };
                    await postCategoryServices.SavePostCategory(postCategory);
                }
            }
        }