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