public async Task <AlunoEditModelReturn> AddAlunoAsync(AlunoEditModel model) { var aluno = new Aluno(); mapper.Map(model, aluno); await alunoRepository.AddAsync(aluno); await context.SaveChangesAsync(); return(mapper.Map(aluno, new AlunoEditModelReturn())); }
public async Task <IActionResult> Post(AlunoEditModel model) { try { if ((await alunoService.AddAlunoAsync(model)) is AlunoEditModelReturn alunoReturnModel) { return(Ok(alunoReturnModel)); } return(BadRequest()); } catch (Exception ex) { return(BadRequest($"Erro: {ex.Message}")); } }
public async Task <AlunoEditModelReturn> UpdateAlunoAsync(int alunoId, AlunoEditModel model) { var aluno = (await alunoRepository.GetAlunoByIdAsync(alunoId)); if (aluno == null) { throw new KeyNotFoundException(); } mapper.Map(model, aluno); await alunoRepository.UpdateAsync(aluno); await context.SaveChangesAsync(); return(mapper.Map(aluno, new AlunoEditModelReturn())); }
public async Task <IActionResult> Put(int alunoId, AlunoEditModel model) { try { if ((await alunoService.UpdateAlunoAsync(alunoId, model)) is AlunoEditModelReturn alunoReturnModel) { return(Ok(alunoReturnModel)); } return(BadRequest()); } catch (KeyNotFoundException) { return(NotFound()); } catch (Exception ex) { return(BadRequest($"Erro: {ex.Message}")); } }