private void Cadastrar(object sender, RoutedEventArgs e) { Emprestimo emp = new Emprestimo(); emp.DataEmprestimo = dataEmprestimo.SelectedDate; emp.DataPrevistaDevolucao = dataPrevDevol.SelectedDate; Pessoa p = PessoaDAO.ObterPessoa(Convert.ToInt32(cboOperador.SelectedValue)); emp.Operador = p; Pessoa pe = PessoaDAO.ObterPessoa(Convert.ToInt32(cboUsuario.SelectedValue)); emp.Usuario = pe; emp.Equipamentos = list; if (EmprestimoDAO.CadastrarEmprestimo(emp)) { MessageBox.Show("Empréstimo realizado com sucesso!"); CarregarEmprestimos(); LimparFormulario(); } else { MessageBox.Show("Empréstimo não realizado"); } }
public ActionResult Create([Bind(Include = "id,livro,valor,cep,endereco")] Emprestimo emprestimo, long matricula, string nome, DateTime dataPrazo) { string url = "https://viacep.com.br/ws/" + emprestimo.cep + "/json/"; WebClient client = new WebClient(); try { Emprestimo aux = new Emprestimo(); string resultado = client.DownloadString(@url); //Converter para UTF8 byte[] bytes = Encoding.Default.GetBytes(resultado); resultado = Encoding.UTF8.GetString(bytes); //Converter os dados da string em objeto aux = JsonConvert.DeserializeObject <Emprestimo>(resultado); emprestimo.endereco = aux.Logradouro + emprestimo.endereco; emprestimo.Bairro = aux.Bairro; emprestimo.Localidade = aux.Localidade; emprestimo.Uf = aux.Uf; emprestimo.Logradouro = aux.Logradouro; } catch { emprestimo.cep = "Cep Inválido"; } emprestimo.status = 0; emprestimo.nome = nome; emprestimo.bibliotecario = BibliotecarioDAO.BuscarBibliotecarioPorMatricula(matricula); if (ModelState.IsValid) { emprestimo.livro.ano = DateTime.Now; emprestimo.dataDevolucao = "26/04/2000 00:00:00"; emprestimo.dataPrazo = Convert.ToString(dataPrazo); EmprestimoDAO.CadastrarEmprestimo(emprestimo); return(RedirectToAction("Index")); } return(View(emprestimo)); }