예제 #1
0
 public PostDetailModelDTO GetPostByComment(CommentDetailModelDTO comment)
 {
     using (var connection = chatterDbContextFactory.CreateDbContext())
     {
         return(mapper.MapEntityToDetailModel(connection.Posts.Where(x => x.Comments.Where(y => x.Id == y.Id).FirstOrDefault() != null).FirstOrDefault()));
     }
 }
예제 #2
0
        public void Create_WithNonExistingItem_DoesNotThrow()
        {
            var model = new CommentDetailModelDTO
            {
                Id = new Guid()
            };

            //var returnedModel = fixture.Repository.AddComment(model);

            Assert.IsNotNull(model);
        }
예제 #3
0
        public bool RemoveComment(CommentDetailModelDTO comment)
        {
            if (comment == null)
            {
                return(false);
            }

            using (var connection = chatterDbContextFactory.CreateDbContext())
            {
                connection.Comments.Remove(mapper.MapDetailToEntity(comment));
                return(connection.SaveChanges() == 1);
            }
        }
예제 #4
0
        public Comment MapDetailToEntity(CommentDetailModelDTO comment)
        {
            if (comment == null)
            {
                return(new Comment());
            }

            return(new Comment()
            {
                Content = comment.Content,
                DateTime = comment.DateTime,
                Id = comment.Id,
                User = MapDetailToEntity(comment.User)
            });
        }
예제 #5
0
        public CommentDetailModelDTO AddComment(CommentDetailModelDTO comment)
        {
            using (var connection = chatterDbContextFactory.CreateDbContext())
            {
                var newComment = mapper.MapDetailToEntity(comment);

                connection.Users.Attach(mapper.MapDetailToEntity(comment.User));

                var post = connection.Posts.Single(x => x.Id == comment.Post.Id);
                newComment.Post = post;
                connection.Posts.Attach(post);

                connection.Comments.Add(newComment);
                connection.SaveChanges();
                return(mapper.MapEntityToDetailModel(newComment));
            }
        }
예제 #6
0
 public bool EditComment(CommentDetailModelDTO comment)
 {
     throw new NotImplementedException();
 }