public async Task <IActionResult> ExcluirConta([FromRoute] int Id) { if (!ModelState.IsValid) { TempData["Mensagem"] = ModelState; TempData["Alerta"] = true; TempData["Classe"] = "atencao"; return(RedirectToAction("Index")); } else { try { ContaService service = new ContaService(); string response = await service.Delete(Id); TempData["Mensagem"] = response; TempData["Alerta"] = true; TempData["Classe"] = "sucesso"; return(RedirectToAction("Index")); } catch (Exception ex) { TempData["Mensagem"] = ex.Message; TempData["Alerta"] = true; TempData["Classe"] = "atencao"; return(RedirectToAction("Index")); } } }
private void button1_Click(object sender, EventArgs e) { AdviceConta confirm = new AdviceConta(); DialogResult result = confirm.ShowDialog(); List <string> Erros = new List <string>(); List <Conta> lstShow = ContaService.List(); if (result == DialogResult.OK) { Conta Conta = ContaService.findConta(int.Parse(txtId.Text)); Erros = ContaService.Delete(Conta); if (Erros.Count > 0) { string textError = ""; foreach (var erro in Erros) { textError += erro + "\r\n"; } MessageBox.Show(textError); } else { MessageBox.Show("Conta deletada com sucesso."); DeleteConta_Load(null, EventArgs.Empty); } } }
public void DeleteTest() { try { contaService.Delete("1"); Assert.True(true); } catch { Assert.True(false); } }
public async Task <IActionResult> Delete(int id) { try { var contaDelete = await _service.Delete(id); return(Ok(contaDelete)); } catch (NotFoundException e) { return(this.StatusCode(StatusCodes.Status404NotFound, $"{e.Message}")); } catch (ArgumentException e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"{e.Message}")); } }