Пример #1
0
        public static Speaker MapSpeaker(this ConferenceDTO.SpeakerRequest speaker)
        {
            var mappedSpeaker = new Speaker
            {
                Name    = speaker.Name,
                Bio     = speaker.Bio,
                WebSite = speaker.WebSite,
            };

            mappedSpeaker.SessionSpeakers =
                speaker.Sessions?.Select(s => new SessionSpeaker
            {
                Speaker = mappedSpeaker,
                Session = s.MapSession()
            })
                .ToList();

            mappedSpeaker.SpeakerImages?.Add(new SpeakerImage
            {
                Speaker = mappedSpeaker,
                Image   = speaker.Image.MapImage()
            });

            return(mappedSpeaker);
        }
Пример #2
0
        public async Task <IActionResult> PutSpeaker(int id, ConferenceDTO.SpeakerRequest input)
        {
            try
            {
                var speaker = await _speakersRepository.UpdateAsync(input.MapSpeaker());

                if (speaker == null)
                {
                    return(NotFound());
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (_speakersRepository.GetByIdAsync(id) == null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <ActionResult <ConferenceDTO.SpeakerResponse> > PostSpeaker(ConferenceDTO.SpeakerRequest input)
        {
            var speaker = await _speakersRepository.AddAsync(input.MapSpeaker());

            return(CreatedAtAction(nameof(GetSpeaker), new { id = speaker.ID }, speaker.MapSpeakerResponse()));
        }