public PostResource GetPost(string id) { var post = _context.Set <Post>().SingleOrDefault(x => x.Id == id); var club = _context.Clubs.Find(post?.ClubId); var postResource = _mapper.Map <PostResource>(post); if (club != null) { postResource.ClubName = club.Name; } return(postResource); }
public IEnumerable <ClubResource> GetAllClubs() { var clubs = _context.Set <Club>().Include(c => c.Posts).ThenInclude(p => p.UserPosts).ToList(); return(clubs.Select(club => _mapper.Map <ClubResource>(club)).ToList()); }