public async Task <IActionResult> Create(Cad_End_Cidade model) { try { ModelState.Remove("Id"); ModelState.Remove("DataInclusao"); if (ModelState.IsValid) { var saved = await _Cidade_Repositorio.CriarAsync(model); if (saved != null) { return(RedirectToAction(nameof(Index))); } return(BadRequest()); } TempData["msgDanger"] = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage)); await carregarDadosView(); return(View(model)); } catch (Exception ex) { await carregarDadosView(); TempData["msgDanger"] = ex.Message; return(View(model)); } }
public async Task <IActionResult> Edit(Cad_End_Cidade model) { try { if (ModelState.IsValid) { var saved = await _Cidade_Repositorio.EditarAsync(model); if (saved != null) { return(RedirectToAction(nameof(Index))); } return(BadRequest()); } TempData["msgDanger"] = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage)); await carregarDadosView(); //ViewData["Endereco"] = _Endereco_Repositorio.GerarSelectList(model.IdEndereco); return(View(model)); } catch (Exception ex) { TempData["msgDanger"] = ex.Message; await carregarDadosView(); return(View(model)); } }
public async Task <bool> DeletarAsync(Cad_End_Cidade modelo) { try { _context.Cad_End_Cidade.Remove(modelo); await _context.SaveChangesAsync(); return(true); } catch (Exception e) { throw e; } }
public async Task <Cad_End_Cidade> EditarAsync(Cad_End_Cidade modelo) { try { _context.Update(modelo); await _context.SaveChangesAsync(); return(modelo); } catch (Exception e) { throw e; } }
public async Task <Cad_End_Cidade> CriarAsync(Cad_End_Cidade modelo) { try { modelo.DataInclusao = DateTime.Now; _context.Add(modelo); await _context.SaveChangesAsync(); return(modelo); } catch (Exception e) { throw e; } }