public async Task <int> Edit(ArticleCommentServiceModel serviceModel) { var dbComment = await this.articleCommentRepository.All().SingleOrDefaultAsync(a => a.Id == serviceModel.Id); if (dbComment == null) { return(0); } dbComment.Content = serviceModel.Content; this.articleCommentRepository.Update(dbComment); int result = await this.articleCommentRepository.SaveChangesAsync(); return(result); }
public async Task <int> Create(ArticleCommentServiceModel articleCommentServiceModel) { var parentCommentId = articleCommentServiceModel.ParentCommentId; if (parentCommentId != null && await this.CheckCommentDepth(parentCommentId) >= MaxCommentNestingDepth) { // Set upper level parent to avoid too much nesting articleCommentServiceModel.ParentCommentId = (await this.articleCommentRepository.All() .SingleOrDefaultAsync(c => c.Id == parentCommentId)).ParentCommentId; } var articleComment = AutoMapperConfig.MapperInstance.Map <BDInSelfLove.Data.Models.ArticleComment>(articleCommentServiceModel); await this.articleCommentRepository.AddAsync(articleComment); await this.articleCommentRepository.SaveChangesAsync(); return(articleComment.Id); }