コード例 #1
0
        public async Task <IActionResult> Post(EventDto eventDto)
        {
            try
            {
                var _event = _mapper.Map <Event>(eventDto);

                _projectRepository.Add(_event);

                if (await _projectRepository.SaveChangesAsync())
                {
                    return(Created($"/api/event/{eventDto.Id}", _mapper.Map <EventDto>(_event)));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de dados Falhou, {ex.Message}"));
            }
            return(BadRequest());
        }
コード例 #2
0
 public async Task <ActionResult> Post(Speaker modelSpeaker)
 {
     try
     {
         _projectRepository.Add(modelSpeaker);
         if (await _projectRepository.SaveChangesAsync())
         {
             return(Created($"/api/speaker/{modelSpeaker.Id}", modelSpeaker));
         }
     }
     catch (System.Exception)
     {
         return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados Falhou"));
     }
     return(BadRequest());
 }