예제 #1
0
        public async Task EditArticle(Guid articleId, string title, string content, Guid[] categoryIds)
        {
            using (var articleSvc = new DAL.ArticleService())
            {
                var article = await articleSvc.GetOneByIdAsync(articleId);

                article.Title   = title;
                article.Content = content;
                await articleSvc.EditAsync(article);
            }
            using (var articleToCategorySvc = new DAL.ArticleToCategoryService())
            {
                foreach (var item in articleToCategorySvc.GetAllAsync().Where(m => m.ArticleId == articleId))
                {
                    await articleToCategorySvc.RemoveAsync(item, false);
                }
                foreach (var item in categoryIds)
                {
                    await articleToCategorySvc.CreateAsync(new Models.ArticleToCategory()
                    {
                        ArticleId = articleId, BlogCategoryId = item
                    }, false);
                }
                await articleToCategorySvc.Save();
            }
        }
예제 #2
0
        public async Task CreateArticle(string title, string content, Guid[] categoryIds, Guid userId)
        {
            using (IDAL.IArticleService articleSvc = new DAL.ArticleService())
            {
                var article = new Models.Article()
                {
                    Title   = title,
                    Content = content,
                    UserId  = userId
                };
                await articleSvc.CreateAsync(article);

                Guid articleId = article.Id;
                using (var articleToCategroySvc = new DAL.ArticleToCategoryService())
                {
                    foreach (var categoryId in categoryIds)
                    {
                        await articleToCategroySvc.CreateAsync(new Models.ArticleToCategory()
                        {
                            ArticleId      = articleId,
                            BlogCategoryId = categoryId
                        }, saved : false);
                    }
                    await articleToCategroySvc.Save();
                }
            }
        }