示例#1
0
        public CommentDetailModel Add(CommentDetailModel detail)
        {
            using (var teamCommunicationDbContext = dbContextFactory.CreateDbContext())
            {
                var comment = CommentMapper.MapCommentDetailModelToEntity(detail);
                comment.Id = Guid.NewGuid();


                Guid idUser = detail.UserId;
                Console.WriteLine("NEW ID:");
                Console.WriteLine(idUser);
                Guid idTopic = detail.TopicId;
                Console.WriteLine("NEW TOPIC ID:");
                Console.WriteLine(idTopic);
                if (idUser != Guid.Empty)
                {
                    comment.User = teamCommunicationDbContext.Users.First(c => c.Id == idUser);
                }
                if (idTopic != Guid.Empty)
                {
                    comment.Topic = teamCommunicationDbContext.Topics.First(c => c.Id == idTopic);
                }
                teamCommunicationDbContext.Comments.Add(comment);
                teamCommunicationDbContext.SaveChanges();

                return(CommentMapper.MapCommentEntityToDetailModel(comment));
            }
        }
示例#2
0
        public CommentDetailModel GetById(Guid id)
        {
            using (var teamCommunicationDbContext = dbContextFactory.CreateDbContext())
            {
                var comment = teamCommunicationDbContext.Comments.Include(e => e.User).Include(e => e.Topic).First(c => c.Id == id);;
                Console.WriteLine("COMM HERE:");
                if (comment.User != null)
                {
                    Console.WriteLine(comment.User.Id);
                }
                Console.WriteLine("TOPIC HERE:");
                if (comment.Topic != null)
                {
                    Console.WriteLine(comment.Topic.Id);
                }

                return(CommentMapper.MapCommentEntityToDetailModel(comment));
            }
        }