public PostDetailModel Create(PostDetailModel postModel, UserDetailModel authorModel) { using (var dbContext = _dbContextFactory.CreateTeamChatDbContext()) { postModel.CreationTime = DateTime.Now; postModel.Author = UserMapper.DetailToListModel(authorModel); var postEntity = PostMapper.MapDetailModelToEntity(postModel); postEntity.Author = UserMapper.MapToEntity(authorModel); var userEntity = dbContext.Users .First(u => u.Id == authorModel.Id); userEntity.Activities.Add(postEntity); dbContext.Users.Update(userEntity); dbContext.Posts.Update(postEntity); dbContext.SaveChanges(); return(PostMapper.MapToDetailModel(postEntity)); } }