예제 #1
0
 public CommentDetailModel GetById(Guid id)
 {
     using (var dbContext = _dbContextFactory.CreateTeamChatDbContext())
     {
         return(CommentMapper.MapToDetailModel(dbContext.Comments
                                               .Include(a => a.Author)
                                               .Include(p => p.BelongsTo)
                                               .ThenInclude(a => a.Author)
                                               .First(e => e.Id == id)));
     }
 }
예제 #2
0
        public CommentDetailModel UpdateContent(CommentDetailModel commentModel, string content)
        {
            using (var dbContext = _dbContextFactory.CreateTeamChatDbContext())
            {
                var commentEntity = dbContext.Comments
                                    .Include(a => a.Author)
                                    .Include(p => p.BelongsTo)
                                    .ThenInclude(a => a.Author)
                                    .First(c => c.Id == commentModel.Id);

                commentEntity.Content = content;
                dbContext.Comments.Update(commentEntity);
                dbContext.SaveChanges();
                return(CommentMapper.MapToDetailModel(commentEntity));
            }
        }
예제 #3
0
        public CommentDetailModel Create(CommentDetailModel commentModel, UserDetailModel authorModel, PostDetailModel postModel)
        {
            using (var dbContext = _dbContextFactory.CreateTeamChatDbContext())
            {
                commentModel.BelongsTo    = PostMapper.DetailToListModel(postModel);
                commentModel.Author       = UserMapper.DetailToListModel(authorModel);
                commentModel.CreationTime = DateTime.Now;

                var userEntity = dbContext.Users
                                 .Include(a => a.Activities)
                                 .First(u => u.Id == commentModel.Author.Id);
                var commentEntity = CommentMapper.MapToEntity(commentModel);
                userEntity.Activities.Add(commentEntity);
                dbContext.Users.Update(userEntity);
                dbContext.Comments.Update(commentEntity);
                dbContext.SaveChanges();

                return(CommentMapper.MapToDetailModel(commentEntity));
            }
        }