// POST - Inserir uma nova ilha public async Task InserirIlha(IlhaModel ilha) { try { _context.Ilhas.Add(ilha); await _context.SaveChangesAsync(); } catch (Exception) { throw; } }
public async Task <ActionResult <IlhaModel> > Post([FromBody] IlhaDTO Ilha) { if (String.IsNullOrEmpty(Ilha.Localizacao)) { return(BadRequest("O campo localização é obrigatório")); } else { try { IlhaModel ilhaModel = new IlhaModel() { Localizacao = Ilha.Localizacao }; await _repository.InserirIlha(ilhaModel); return(CreatedAtAction(nameof(CarregarIlha), new { Id = ilhaModel.Id }, ilhaModel)); } catch (Exception e) { return(BadRequest(e.Message)); } } }