예제 #1
0
        public ActionResult Delete(int id)
        {
            PessoaService srv = new PessoaService();

            srv.Delete(id);
            return(View("List", new List <Pessoa>()));
        }
예제 #2
0
        public async Task <IActionResult> ExcluirPerfil([FromRoute] int Id)
        {
            if (!ModelState.IsValid)
            {
                TempData["Mensagem"] = ModelState;
                TempData["Alerta"]   = true;
                TempData["Classe"]   = "atencao";
                return(RedirectToAction("Index"));
            }
            else
            {
                try
                {
                    PessoaService service  = new PessoaService();
                    string        response = await service.Delete(Id);

                    TempData["Mensagem"] = response;
                    TempData["Alerta"]   = true;
                    TempData["Classe"]   = "sucesso";
                    HttpContext.Session.Clear();
                    return(RedirectToAction("Index", "Login", new { area = "" }));
                }
                catch (Exception ex)
                {
                    TempData["Mensagem"] = ex.Message;
                    TempData["Alerta"]   = true;
                    TempData["Classe"]   = "atencao";
                    return(RedirectToAction("Index"));
                }
            }
        }
예제 #3
0
 public ActionResult Delete(int Id)
 {
     if (_pessoaService.Delete(Id))
     {
         return(Ok());
     }
     return(BadRequest("Pessoa de ID " + Id + " não existe no banco de dados"));
 }
예제 #4
0
        public async Task <IActionResult> Delete(int id)
        {
            try {
                var pessoaDelete = await _service.Delete(id);

                return(Ok(pessoaDelete));
            }
            catch (NotFoundException e) {
                return(this.StatusCode(StatusCodes.Status404NotFound, $"{e.Message}"));
            }
            catch (ArgumentException e) {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"{e.Message}"));
            }
        }
 public void Delete(Guid id)
 {
     _service.Delete(id);
 }
예제 #6
0
 public ActionResult <PessoaModel> DeletePessoaModel(int id)
 {
     return(Ok(_pessoaservice.Delete(id)));
 }
예제 #7
0
        static void Main(string[] args)
        {
            string        path = Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            int           n;
            var           start         = 0;
            var           loop          = true;
            var           vListaPessoas = new List <Pessoa>();
            PessoaService ServicoPessoa = new PessoaService();
            DateTime      DataHoje      = Convert.ToDateTime(DateTime.Now.ToString("dd/MM/yyyy"));

            ExibeFuncionalidades();
            var  vTemp  = Console.ReadLine();
            bool result = Int32.TryParse(vTemp, out n);

            if (result)
            {
                start = Convert.ToInt32(vTemp);
            }
            else
            {
                start = 99;
            }


            while (loop)
            {
                switch (start)
                {
                case 0:
                    ExibeFuncionalidades();
                    vTemp  = Console.ReadLine();
                    result = Int32.TryParse(vTemp, out n);
                    if (result)
                    {
                        start = Convert.ToInt32(vTemp);
                    }
                    else
                    {
                        start = 99;
                    }
                    break;

                case 1:
                    var ListDeRegistros = ServicoPessoa.GetAll();
                    int vId             = ListDeRegistros.Count;
                    var pessoa          = new Pessoa();
                    Console.WriteLine("Digite o nome:");
                    pessoa.NM_NOME = Console.ReadLine();
                    Console.WriteLine("Digite o SobreNome:");
                    pessoa.NM_SOBRENOME = Console.ReadLine();
                    Console.WriteLine("Digite o aniversário: ex(dd/mm/yyyy)");
                    var date = Console.ReadLine().Split('/');
                    while (date.Length != 3)
                    {
                        Console.WriteLine("Digite o aniversário no formato: (dd/mm/yyyy) para prosseguir: ");
                        date = Console.ReadLine().Split('/');
                    }
                    pessoa.DT_NASCIMENTO = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0]));

                    if (vId != 0)
                    {
                        var vPessoa = ListDeRegistros[vId - 1];
                        vId       = vPessoa.ID + 1;
                        pessoa.ID = vId;
                    }
                    else
                    {
                        pessoa.ID = vId;
                    }


                    ServicoPessoa.Create(pessoa);
                    //REGIÃO AONDE SERÁ TUDO SALVO NEM UM ARQUIVO EM BRANCO
                    ListDeRegistros = ServicoPessoa.GetAll();
                    var    json          = JsonConvert.SerializeObject(ListDeRegistros, Formatting.Indented);
                    string PathRelatorio = Path.Combine(path, "relatorio.txt");
                    if (File.Exists(PathRelatorio))
                    {
                        StreamWriter sw = new StreamWriter(PathRelatorio.ToString());
                        sw.WriteLine(json);
                        sw.Close();
                    }
                    else
                    {
                        StreamWriter sw = new StreamWriter(PathRelatorio.ToString(), true, Encoding.UTF8);
                        sw.WriteLine(json);
                        sw.Close();
                    }

                    start = 0;
                    break;

                case 2:
                    var vRetornoAtualiza = SolicitaNomeBuscar();
                    Console.WriteLine("--- RESULTADO ---");
                    vListaPessoas = ServicoPessoa.GetByName(vRetornoAtualiza[0]);
                    if (vListaPessoas != null && vListaPessoas.Count != 0)
                    {
                        Console.WriteLine(JsonConvert.SerializeObject(vListaPessoas, Formatting.Indented));
                        Console.WriteLine("Selecione o ID da pessoa que deseja EDITAR:");
                        var vIndex = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Carregando...");
                        var vRetornoPessoa = ServicoPessoa.GetById(vIndex);
                        if (vRetornoPessoa.ID != -1)
                        {
                            Console.WriteLine("Digite novo nome:");
                            vRetornoPessoa.NM_NOME = Console.ReadLine();
                            Console.WriteLine("Digite novo SobreNome:");
                            vRetornoPessoa.NM_SOBRENOME = Console.ReadLine();
                            Console.WriteLine("Digite novo aniversário: ex(dd/mm/yyyy)");
                            var vDate = Console.ReadLine().Split('/');
                            vRetornoPessoa.DT_NASCIMENTO = new DateTime(Convert.ToInt32(vDate[2]), Convert.ToInt32(vDate[1]), Convert.ToInt32(vDate[0]));
                            ServicoPessoa.Update(vRetornoPessoa, vIndex);
                        }
                        else
                        {
                            Console.WriteLine($"Não foi encontrado uma pessoa com o ID: {vIndex}.");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Não foi encontrado uma pessoa com o nome: {vRetornoAtualiza[0]}.");
                    }

                    start = 0;
                    break;

                case 3:
                    var vRetornoExcluir = SolicitaNomeBuscar();
                    Console.WriteLine("--- RESULTADO ---");
                    vListaPessoas = ServicoPessoa.GetByName(vRetornoExcluir[0]);
                    if (vListaPessoas != null && vListaPessoas.Count != 0)
                    {
                        Console.WriteLine(JsonConvert.SerializeObject(vListaPessoas, Formatting.Indented));
                        Console.WriteLine("Selecione o ID da pessoa que deseja APAGAR:");
                        var vIndex = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Carregando...");
                        var vRetornoPessoa = ServicoPessoa.GetById(vIndex);
                        if (vRetornoPessoa.ID != -1)
                        {
                            ServicoPessoa.Delete(vRetornoPessoa);
                        }
                        else
                        {
                            Console.WriteLine($"Não foi encontrado uma pessoa com o ID: {vIndex}.");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Não foi encontrado uma pessoa com o nome: {vRetornoExcluir[0]}.");
                    }

                    start = 0;
                    break;

                case 4:
                    Console.WriteLine("Digite o ID da pessoa que deseja Buscar:");
                    var vRetornoBuscarPorID = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("--- RESULTADO ---");
                    var vPessoaByID = ServicoPessoa.GetById(vRetornoBuscarPorID);
                    if (vPessoaByID.ID != -1)
                    {
                        var vData = Data.CalculaPeriodo(vPessoaByID.DT_NASCIMENTO, DataHoje);
                        Console.WriteLine(JsonConvert.SerializeObject(vPessoaByID, Formatting.Indented));
                        if (vData.NR_DIAS == 0)
                        {
                            Console.WriteLine($"Parabéns {Regex.Replace(vPessoaByID.NM_NOME, @"\s+", "")} seu aniversário é hoje !!! Felicidades !!! \n");
                        }
                        else
                        {
                            Console.WriteLine($"Para o aniversário do {vPessoaByID.NM_NOME} faltam: {vData.NR_DIAS} Dias e será : {vData.NM_DIA}.\n");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Não foi encontrado uma pessoa com o ID: {vRetornoBuscarPorID}.");
                    }

                    start = 0;
                    break;

                case 5:
                    Console.WriteLine("Você está preste a DELETAR todos do banco de dados.");
                    Console.WriteLine("Deseja continuar ?(S/N)");
                    var vConfirmaDelete = Console.ReadLine();
                    if (vConfirmaDelete == "S")
                    {
                        vListaPessoas = ServicoPessoa.GetAll();
                        foreach (var Pessoa in vListaPessoas)
                        {
                            ServicoPessoa.Delete(Pessoa);
                        }
                    }

                    start = 0;
                    break;

                default:
                    if (vTemp == "q")
                    {
                        loop = false;
                    }
                    else
                    {
                        start = 0;
                    }
                    break;
                }
            }
        }
예제 #8
0
 //[Authorize("Bearer")]
 public IActionResult Delete(string id)
 {
     _pessoaService.Delete(id);
     return(Ok());
 }