コード例 #1
0
        public async Task <IActionResult> AssignCategory(List <AssignCategoryModel> list)
        {
            TempData["Active"] = ActivePage.Blog;
            int id = (int)TempData["blogId"];

            foreach (var item in list)
            {
                if (item.Exists)
                {
                    var model = new CategoryBlogDto
                    {
                        BlogId     = id,
                        CategoryId = item.CategoryId
                    };

                    await _blogService.AddToCategoryAsync(model);
                }
                else
                {
                    var model = new CategoryBlogDto
                    {
                        BlogId     = id,
                        CategoryId = item.CategoryId
                    };

                    await _blogService.RemoveFromCategoryAsync(model);
                }
            }

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task RemoveFromCategoryAsync(CategoryBlogDto categoryBlogDto)
        {
            var deletedCategory = await _categoryDal.GetAsync(I => I.CategoryId == categoryBlogDto.CategoryId && I.BlogId == categoryBlogDto.BlogId);

            if (deletedCategory != null)
            {
                await _categoryDal.RemoveAsync(deletedCategory);
            }
        }
コード例 #3
0
        public async Task AddToCategoryAsync(CategoryBlogDto categoryBlogDto)
        {
            var control = await _categoryDal.GetAsync(I => I.BlogId == categoryBlogDto.BlogId && I.CategoryId == categoryBlogDto.CategoryId);

            if (control == null)
            {
                await _categoryDal.AddAsync(new CategoryBlog { BlogId = categoryBlogDto.BlogId, CategoryId = categoryBlogDto.CategoryId });
            }
        }
コード例 #4
0
        public async Task RemoveToCategoryAsync(CategoryBlogDto categoryBlogDto)
        {
            var deletedCategoryBlog = await _categoryBlogService.GetAsync(I => I.CategoryId == categoryBlogDto.CategoryId && I.BlogId == categoryBlogDto.ArticleId);

            if (deletedCategoryBlog != null)
            {
                await _categoryBlogService.RemoveAsync(deletedCategoryBlog);
            }
        }
コード例 #5
0
        public async Task RemoveFromCategoryAsync(CategoryBlogDto categoryBlogDto)
        {
            var categoryBlog = await _categoryBlogService.GetAsync(p => p.CategoryId == categoryBlogDto.CategoryId && p.BlogId == categoryBlogDto.BlogId);

            if (categoryBlog != null)
            {
                await _categoryBlogService.RemoveAsync(categoryBlog);
            }
        }
コード例 #6
0
        public async Task AddToCategoryAsync(CategoryBlogDto categoryBlogDto)
        {
            var addToCategory = await _categoryBlogDal.GetAsync(i => i.BlogId == categoryBlogDto.BlogId && i.CategoryId == categoryBlogDto.CategoryId);

            if (addToCategory == null)
            {
                await _categoryBlogDal.AddAsync(new CategoryBlog
                {
                    BlogId     = categoryBlogDto.BlogId,
                    CategoryId = categoryBlogDto.CategoryId
                });
            }
        }
コード例 #7
0
ファイル: BlogManager.cs プロジェクト: erolaksoy/blog-app-mvc
        public async Task AddToCategoryAsync(CategoryBlogDto categoryBlogDto)
        {
            var control = await _categoryBlogDal.GetAsync(x => x.CategoryId == categoryBlogDto.CategoryId && x.BlogId == categoryBlogDto.BlogId);

            if (control == null)
            {
                await _categoryBlogDal.InsertAsync(new CategoryBlog
                {
                    BlogId     = categoryBlogDto.BlogId,
                    CategoryId = categoryBlogDto.CategoryId
                });
            }
        }
コード例 #8
0
        public async Task AddToCategoryAsync(CategoryBlogDto categoryBlogDto)
        {
            var control = await _categoryBlogService.GetAsync(p => p.CategoryId == categoryBlogDto.CategoryId && p.BlogId == categoryBlogDto.BlogId);

            if (control == null)
            {
                await _categoryBlogService.AddAsync(
                    new CategoryBlog
                {
                    BlogId     = categoryBlogDto.BlogId,
                    CategoryId = categoryBlogDto.CategoryId
                }
                    );
            }
        }
コード例 #9
0
        public async Task <IActionResult> RemoveFromCategory([FromQuery] CategoryBlogDto categoryBlogDto)
        {
            await _blogService.RemoveFromCategoryAsync(categoryBlogDto);

            return(NoContent());
        }
コード例 #10
0
        public async Task <IActionResult> AddToCategory(CategoryBlogDto categoryBlogDto)
        {
            await _blogService.AddToCategoryAsync(categoryBlogDto);

            return(Created("", categoryBlogDto));
        }
コード例 #11
0
        public async Task <IActionResult> RemoveFromCategory(CategoryBlogDto model)
        {
            await _blogService.RemoveFromCategoryAsync(model);

            return(NoContent());
        }
コード例 #12
0
        public async Task <IActionResult> AddToCategory(CategoryBlogDto model)
        {
            await _blogService.AddToCategoryAsync(model);

            return(Created("", model));
        }