示例#1
0
        public async Task <IActionResult> CreateSpeaker(ConferenceDTO.Speaker input)
        {
            var speaker = new Data.Speaker
            {
                Name    = input.Name,
                WebSite = input.WebSite,
                Bio     = input.Bio
            };

            _db.Speakers.Add(speaker);
            await _db.SaveChangesAsync();

            var result = speaker.MapSpeakerResponse();

            return(CreatedAtAction(nameof(GetSpeaker), new { id = speaker.ID }, result));
        }
示例#2
0
        public async Task <IActionResult> PutSpeaker(int id, ConferenceDTO.Speaker input)
        {
            var speaker = await _db.FindAsync <Data.Speaker>(id);

            if (speaker == null)
            {
                return(NotFound());
            }

            speaker.Name    = input.Name;
            speaker.WebSite = input.WebSite;
            speaker.Bio     = input.Bio;

            // TODO: Handle exceptions, e.g. concurrency
            await _db.SaveChangesAsync();

            return(NoContent());
        }
示例#3
0
        public async Task <IActionResult> Put(int id, ConferenceDTO.Speaker input)
        {
            var speaker = await _context.Speakers.FindAsync(id);

            if (speaker == null)
            {
                return(NotFound());
            }

            speaker.Id      = input.Id;
            speaker.Name    = input.Name;
            speaker.Bio     = input.Bio;
            speaker.WebSite = input.WebSite;

            await _context.SaveChangesAsync();

            return(NoContent());
        }