public async Task <IActionResult> Edit(int id, Membro membro) { if (!ModelState.IsValid) { var oscs = await _oscService.FindAllAsync(); var viewModel = new OscFormViewModel { Membro = membro, Oscs = oscs }; return(View(viewModel)); } if (id != membro.Id) { return(RedirectToAction(nameof(Error), new { message = "Id não corresponde!" })); } try { await _membroService.UpdateAsync(membro); return(RedirectToAction(nameof(Index))); } catch (ApplicationException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> Create() { var oscs = await _oscService.FindAllAsync(); var viewModel = new OscFormViewModel { Oscs = oscs }; return(View(viewModel)); }
public async Task <IActionResult> Create(Membro membro) { if (!ModelState.IsValid) { var oscs = await _oscService.FindAllAsync(); var viewModel = new OscFormViewModel { Membro = membro, Oscs = oscs }; return(View(viewModel)); } await _membroService.InsertAsync(membro); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), new { message = "Id não fornecido!" })); } var obj = await _membroService.FindByIdAsync(id.Value); if (obj == null) { return(RedirectToAction(nameof(Error), new { message = "Id não encontrado!" })); } List <Osc> oscs = await _oscService.FindAllAsync(); OscFormViewModel viewModel = new OscFormViewModel { Membro = obj, Oscs = oscs }; return(View(viewModel)); }