public IActionResult Edit(int id, Aluno aluno) { if (!ModelState.IsValid) // verificacao, validando dados { var turmas = _turmaService.FindAll(); var viewModel = new AlunoFormViewModel { Aluno = aluno, Turmas = turmas }; return(View(viewModel)); } if (id != aluno.Id) { return(RedirectToAction(nameof(Error), new { message = "Id incompatível." })); } try { _alunoService.Update(aluno); return(RedirectToAction(nameof(Index))); } catch (ApplicationException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> Edit(int id, Aluno aluno) { if (!ModelState.IsValid) { var turmas = await _turmaService.FindAllAsync(); var viewModel = new AlunoFormViewModel { Aluno = aluno, Turmas = turmas }; return(View(viewModel)); } if (id != aluno.Id) { return(RedirectToAction(nameof(Error), new { message = "Id não se correspondem" })); } try { await _alunoService.UpdateAsync(aluno); return(RedirectToAction(nameof(Index))); } catch (ApplicationException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } /*catch (DbConcurrencyException e) * { * return RedirectToAction(nameof(Error), new { message = e.Message }); * }*/ }
public async Task <IActionResult> Edit(int id, Aluno aluno) { if (!ModelState.IsValid) { var cursos = await _cursoService.FindAllAsync(); var viewModel = new AlunoFormViewModel { Cursos = cursos }; return(View(viewModel)); } if (id != aluno.Id) { return(RedirectToAction(nameof(Error), new { message = "Id mismatch" })); } try { await _alunoService.UpdateAsync(aluno); return(RedirectToAction(nameof(Index))); } catch (NotFoundException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } catch (DbConcurrencyException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public IActionResult Create() { var turmas = _turmaService.FindAll(); var viewModel = new AlunoFormViewModel { Turmas = turmas }; return(View(viewModel)); }
public async Task <IActionResult> Create() { var turmas = await _turmaService.FindAllAsync(); var viewModel = new AlunoFormViewModel { Turmas = turmas }; return(View(viewModel)); }
public async Task <IActionResult> Create() { var cursos = await _cursoService.FindAllAsync(); var viewModel = new AlunoFormViewModel { Cursos = cursos }; return(View(viewModel)); }
public async Task <IActionResult> Post([FromBody] AlunoFormViewModel model) { var result = await _alunoService.Cadastrar(_mapper.Map <Aluno>(model)); if (result.IsValid) { return(Ok(_mapper.Map <AlunoViewModel>(result.Entity))); } return(BadRequest(result.Result)); }
public IActionResult Create(Aluno aluno) { if (!ModelState.IsValid) // verificacao, validando dados { var turmas = _turmaService.FindAll(); var viewModel = new AlunoFormViewModel { Aluno = aluno, Turmas = turmas }; return(View(viewModel)); } _alunoService.Insert(aluno); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(Aluno aluno) { if (!ModelState.IsValid) { var turmas = await _turmaService.FindAllAsync(); var viewModel = new AlunoFormViewModel { Aluno = aluno, Turmas = turmas }; return(View(viewModel)); } await _alunoService.InsertAsync(aluno); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Put(Guid id, [FromBody] AlunoFormViewModel model) { if (!await _alunoService.Existe(id)) { return(RegistroNaoEncontrado(id)); } var result = await _alunoService.Editar(id, _mapper.Map <Aluno>(model)); if (result.IsValid) { return(Ok(_mapper.Map <AlunoViewModel>(result.Entity))); } return(BadRequest(result.Result)); }
public IActionResult Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), new { message = "Id não fornecido." })); } var aluno = _alunoService.FindById(id.Value); if (aluno == null) { return(RedirectToAction(nameof(Error), new { message = "Id não encontrado." })); } List <Turma> turmas = _turmaService.FindAll(); AlunoFormViewModel viewModel = new AlunoFormViewModel { Aluno = aluno, Turmas = turmas }; return(View(viewModel)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), new { message = "Id not provided" })); } var obj = await _alunoService.FindByIdAsync(id.Value); if (obj == null) { return(RedirectToAction(nameof(Error), new { messsage = "Id not found" })); } List <Curso> cursos = await _cursoService.FindAllAsync(); AlunoFormViewModel viewModel = new AlunoFormViewModel { Aluno = obj, Cursos = cursos }; return(View(viewModel)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), new { message = "Id não foi fornecido" })); } var obj = await _alunoService.FindByIdAsync(id.Value); if (obj == null) { return(RedirectToAction(nameof(Error), new { message = "Id não encontrado" })); } List <Turma> turmas = await _turmaService.FindAllAsync(); AlunoFormViewModel viewModel = new AlunoFormViewModel { Aluno = obj, Turmas = turmas }; return(View(viewModel)); }