Beispiel #1
0
        public TopicDetailModel GetById(Guid id)
        {
            using (var teamCommunicationDbContext = dbContextFactory.CreateDbContext())
            {
                var topic = teamCommunicationDbContext.Topics.Include(e => e.Team).Include(e => e.User).First(c => c.Id == id);

                return(TopicMapper.MapTopicEntityToDetailModel(topic));
            }
        }
Beispiel #2
0
        public TopicDetailModel Add(TopicDetailModel detail)
        {
            using (var teamCommunicationDbContext = dbContextFactory.CreateDbContext())
            {
                var topic = TopicMapper.MapTopicDetailModelToEntity(detail);
                topic.Id = Guid.NewGuid();
                var idUser = detail.UserId;
                var idTeam = detail.TeamId;
                if (idUser != Guid.Empty)
                {
                    topic.User = teamCommunicationDbContext.Users.First(c => c.Id == idUser);
                }
                if (idTeam != Guid.Empty)
                {
                    topic.Team = teamCommunicationDbContext.Teams.First(c => c.Id == idTeam);
                }

                teamCommunicationDbContext.Topics.Add(topic);
                teamCommunicationDbContext.SaveChanges();

                return(TopicMapper.MapTopicEntityToDetailModel(topic));
            }
        }