Exemplo n.º 1
0
        public async Task <IHttpActionResult> Post(string moniker, TalkViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var camp = await _repository.GetCampAsync(moniker);

            var speaker = await _repository.GetSpeakerAsync(viewModel.Speaker.Id);

            var talk = _mapper.Map <Talk>(viewModel);

            talk.Camp = camp;

            talk.Speaker = speaker;

            await _repository.AddTalkAsync(talk);

            await _repository.SaveChangesAsync();

            var createdTalkViewModel = _mapper.Map <TalkViewModel>(talk);

            return(CreatedAtRoute("GetTalk", new { moniker = camp.Moniker, id = createdTalkViewModel.Id }, createdTalkViewModel));
        }