Ejemplo n.º 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));
            }
        }