public async Task <IActionResult> Edit(int id, Autonomo autonomo) { if (!ModelState.IsValid) { AutonomoFormViewModel viewModel = new AutonomoFormViewModel { Autonomo = autonomo }; return(View(viewModel)); } if (id != autonomo.Id) { return(BadRequest()); } try { autonomo.EmpresaId = int.Parse(EmpresaId); await _autonomoService.UpdateAsync(autonomo); return(RedirectToAction(nameof(Index))); } catch (ApplicationException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> Create() { var empresas = await _empresaService.FindAllAsync(); AutonomoFormViewModel viewModel = new AutonomoFormViewModel { Empresas = empresas }; return(View(viewModel)); }
public async Task <IActionResult> Create(Autonomo autonomo) { if (!ModelState.IsValid) { var viewModel = new AutonomoFormViewModel(); return(View(viewModel)); } autonomo.EmpresaId = int.Parse(EmpresaId); await _autonomoService.InsertAsync(autonomo); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Delete(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), new { message = "Id não informado!" })); } var obj = await _autonomoService.FindByIdAsync(EmpresaId, id.Value); if (obj == null) { return(RedirectToAction(nameof(Error), new { message = "Id não encontrado!" })); } AutonomoFormViewModel viewModel = new AutonomoFormViewModel { Autonomo = obj }; return(View(viewModel)); }