コード例 #1
0
        public IActionResult CadastrarImovel(Imovel imovel, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    string arquivo = $"{Guid.NewGuid()}{Path.GetExtension(file.FileName)}";
                    string caminho = Path.Combine(_hosting.WebRootPath, "Images", arquivo);
                    string dbImage = $"\\Images\\{arquivo}";
                    file.CopyTo(new FileStream(caminho, FileMode.CreateNew));
                    imovel.Imagem = dbImage;
                }
                else
                {
                    imovel.Imagem= "/Images/semimagem.gif";
                }

                _imovelDAO.Cadastrar(imovel);
                return RedirectToAction("CardsImoveis", "Imovel");

            }
            ModelState.AddModelError("", "Não foi possível cadastrar imóvel tente novamente!");
            return View(imovel);
         
        }
コード例 #2
0
 private void BtnSalvar_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(txtArea.Text) || !string.IsNullOrWhiteSpace(txtCEP.Text) || !string.IsNullOrWhiteSpace(txtCidade.Text) ||
         !string.IsNullOrWhiteSpace(txtComissao.Text) || !string.IsNullOrWhiteSpace(txtDescricao.Text) || !string.IsNullOrWhiteSpace(txtRua.Text) ||
         !string.IsNullOrWhiteSpace(txtUF.Text) || !string.IsNullOrWhiteSpace(txtValorAluguel.Text))
     {
         Imovel = new Imovel()
         {
             Area         = Convert.ToDouble(txtArea.Text),
             Cidade       = txtCidade.Text,
             Endereco     = txtRua.Text,
             Locado       = false,
             UF           = txtUF.Text,
             ValorAluguel = Convert.ToDouble(txtValorAluguel.Text),
             TipoImovel   = new TipoImovel()
             {
                 Comissao  = Convert.ToInt32(txtComissao.Text),
                 Descricao = txtDescricao.Text
             }
         };
         if (ImovelDAO.Cadastrar(Imovel))
         {
             MessageBox.Show("Imóvel salvo com sucesso!", "Imob",
                             MessageBoxButton.OK, MessageBoxImage.Information);
             LimparFormulario();
         }
         else
         {
             MessageBox.Show("Erro interno: contate um ADM!", "Imob",
                             MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else
     {
         MessageBox.Show("Todos os campos são obrigatórios", "Imob",
                         MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }