コード例 #1
0
 public Task <TalkVm> GetTalk(string talkId)
 => _talkService.GetTalkAsync(talkId);
コード例 #2
0
        public async Task <CompositeModel> GetMeetup([FromRoute] string meetupId, [FromBody] RandomConcatModel descriptor = null)
        {
            var meetup = await _meetupService.GetMeetupAsync(meetupId).ConfigureAwait(true);

            descriptor            = descriptor ?? new RandomConcatModel();
            descriptor.VenueId    = descriptor.VenueId;
            descriptor.Sessions   = descriptor.Sessions ?? new List <SessionVm>();
            descriptor.TalkIds    = descriptor.TalkIds ?? new List <string>();
            descriptor.SpeakerIds = descriptor.SpeakerIds ?? new List <string>();
            descriptor.FriendIds  = descriptor.FriendIds ?? new List <string>();

            if (meetup != null && descriptor.Sessions.Count == 0)
            {
                descriptor.Sessions = meetup.Sessions;
            }

            descriptor.TalkIds.AddRange(descriptor.Sessions.Select(x => x.TalkId).Where(x => !string.IsNullOrWhiteSpace(x)));

            // talks
            var talks = new Dictionary <string, TalkVm>();

            foreach (var talkId in descriptor.TalkIds.Distinct())
            {
                var talk = await _talkService.GetTalkAsync(talkId).ConfigureAwait(true);

                talks.Add(talkId, talk);
            }

            // speakers
            descriptor.SpeakerIds.AddRange(
                talks.Select(x => x.Value).SelectMany(x => x.SpeakerIds.Select(s => s.SpeakerId))
                );
            var speakers = new Dictionary <string, SpeakerVm>();

            foreach (var speakerId in descriptor.SpeakerIds.Distinct())
            {
                var speaker = await _speakerService.GetSpeakerAsync(speakerId).ConfigureAwait(true);

                speakers.Add(speakerId, speaker);
            }

            // friends
            if (meetup != null && descriptor.FriendIds.Count == 0)
            {
                descriptor.FriendIds.AddRange(meetup.FriendIds.Select(x => x.FriendId));
            }

            var friends = new List <Friend>();

            foreach (var friendId in descriptor.FriendIds.Distinct())
            {
                var friend = await _friendService.GetFriendAsync(friendId).ConfigureAwait(true);

                friends.Add(friend);
            }

            // name
            if (string.IsNullOrWhiteSpace(descriptor.Name))
            {
                descriptor.Name = meetup?.Name;
            }

            // venue
            descriptor.VenueId = descriptor.VenueId ?? meetup?.VenueId;
            VenueVm venue = null;

            if (!string.IsNullOrWhiteSpace(descriptor.VenueId))
            {
                venue = await _venueService.GetVenueAsync(descriptor.VenueId).ConfigureAwait(true);
            }

            // community
            if (string.IsNullOrWhiteSpace(descriptor.CommunityId))
            {
                descriptor.CommunityId = meetup?.CommunityId.ToString();
            }

            return(new CompositeModel
            {
                Id = meetup?.Id,
                Name = descriptor.Name,
                CommunityId = string.IsNullOrWhiteSpace(descriptor.CommunityId)
                    ? (Community?)null
                    : descriptor.CommunityId.GetCommunity(),
                Venue = venue,
                Sessions = descriptor.Sessions,
                Talks = talks,
                Speakers = speakers,
                Friends = friends
            });
        }