Exemple #1
0
        static void Main(string[] args)
        {
            Banco        banco = new Banco();
            Banco_Regiao br    = new Banco_Regiao();

            var json = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"\imobiliaria.json");

            var modelo = JsonConvert.DeserializeObject <List <Modelo.Modelo> >(json);

            foreach (var obj in modelo.ToList())
            {
                //Tratando de dados do Tipo Faixa

                #region Faixa Area Total
                //Verificando a faixa da area total do imovel
                var areat   = Convert.ToDecimal(obj.area_total);
                var areatot = string.Empty;

                if (!String.IsNullOrEmpty(obj.area_total))
                {
                    if (areat > 0 && areat <= 40)
                    {
                        areatot = "Entre 0 - 40 metros";
                    }
                    else if (areat > 40 && areat <= 70)
                    {
                        areatot = "Entre 41 - 70 metros";
                    }
                    else if (areat > 71 && areat <= 110)
                    {
                        areatot = "Entre 71 - 110 metros";
                    }
                    else
                    {
                        areatot = "Acima de 111 metros";
                    }
                }
                #endregion

                #region Faixa Area Privada
                //Verificando a faixa da area privada do imovel
                var areap   = Convert.ToDecimal(obj.area_privativa);
                var areapri = string.Empty;

                if (!String.IsNullOrEmpty(obj.area_privativa))
                {
                    if (areap > 0 && areap <= 40)
                    {
                        areapri = "Entre 0 - 40 metros";
                    }
                    else if (areap > 40 && areap <= 70)
                    {
                        areapri = "Entre 41 - 70 metros";
                    }
                    else if (areap > 71 && areap <= 110)
                    {
                        areapri = "Entre 71 - 110 metros";
                    }
                    else
                    {
                        areapri = "Acima de 111 metros";
                    }
                }
                #endregion

                #region Faixa Preço IPTU
                //Verificando a faixa de preço do IPTU do imovel
                var iptu  = Convert.ToDecimal(obj.iptu);
                var fiptu = string.Empty;

                if (!String.IsNullOrEmpty(obj.iptu))
                {
                    if (iptu > 0 && iptu <= 600)
                    {
                        fiptu = "Entre 0 - 600 valores";
                    }
                    else if (iptu > 600 && iptu <= 1200)
                    {
                        fiptu = "Entre 601 - 1200 valores";
                    }
                    else if (iptu > 1200 && iptu <= 1800)
                    {
                        fiptu = "Entre 1201 - 1800 valores";
                    }
                    else
                    {
                        fiptu = "Acima de 1801 valores";
                    }
                }

                #endregion

                #region Faixa Condominio
                //Verificando a faixa de condominio do imovel
                var cond  = Convert.ToDecimal(obj.condominio);
                var condo = string.Empty;

                if (!String.IsNullOrEmpty(obj.condominio))
                {
                    if (cond > 0 && cond <= 100)
                    {
                        condo = "Entre 0 - 100 metros";
                    }
                    else if (cond > 100 && cond <= 150)
                    {
                        condo = "Entre 101 - 150 metros";
                    }
                    else if (cond > 151 && cond <= 200)
                    {
                        condo = "Entre 151 - 200 metros";
                    }
                    else
                    {
                        condo = "Acima de 201 metros";
                    }
                }
                #endregion

                #region Faixa Dormitorios
                //Verificando a faixa de dormitorios do imovel
                var dorm  = Convert.ToInt32(obj.dormitorios);
                var torio = string.Empty;

                if (!String.IsNullOrEmpty(obj.dormitorios))
                {
                    if (dorm > 0 && dorm <= 2)
                    {
                        torio = "Entre 0 - 2 dormitorios";
                    }
                    else if (dorm > 2 && dorm <= 4)
                    {
                        torio = "Entre 3 - 4" +
                                " dormitorios";
                    }
                    else
                    {
                        torio = "Acima de 5 dormitorios";
                    }
                }
                #endregion

                #region Faixa Suites
                //Verificando a faixa de suites do imovel
                var suit   = Convert.ToInt32(obj.suites);
                var suites = string.Empty;

                if (!String.IsNullOrEmpty(obj.suites))
                {
                    if (suit > 0 && suit <= 2)
                    {
                        suites = "Entre 0 - 2 suites";
                    }
                    else if (suit > 2 && suit <= 4)
                    {
                        suites = "Entre 3 - 4 suites";
                    }
                    else
                    {
                        suites = "Acima de 5 suites";
                    }
                }
                #endregion

                #region Faixa Vagas
                //Verificando a faixa de vagas do imovel
                var vagas  = Convert.ToInt32(obj.vagas);
                var carros = string.Empty;

                if (!String.IsNullOrEmpty(obj.vagas))
                {
                    if (vagas > 0 && vagas <= 2)
                    {
                        carros = "Entre 0 - 2 vagas";
                    }
                    else if (vagas > 2 && vagas <= 4)
                    {
                        carros = "Entre 3 - 4 vagas";
                    }
                    else
                    {
                        carros = "Acima de 5 vagas";
                    }
                }
                #endregion

                #region Faixa Banheiros
                //Verificando a faixa de banheiros do imovel
                var banh   = Convert.ToInt32(obj.banheiros);
                var eirros = string.Empty;

                if (!String.IsNullOrEmpty(obj.banheiros))
                {
                    if (banh > 0 && banh <= 2)
                    {
                        eirros = "Entre 0 - 2 banheiros";
                    }
                    else if (banh > 2 && banh <= 4)
                    {
                        eirros = "Entre 3 - 4 banheiros";
                    }
                    else
                    {
                        eirros = "Acima de 5 banheiros";
                    }
                }
                #endregion

                #region Faixa Valor Venda
                //Verificando a faixa do valor de venda do imovel
                var valor  = Convert.ToDecimal(obj.valor_venda);
                var venda  = string.Empty;
                var padrao = string.Empty;

                if (!String.IsNullOrEmpty(obj.valor_venda))
                {
                    if (valor > 0 && valor <= 50000)
                    {
                        venda  = "Entre 0 - 50.000 valores";
                        padrao = "Básico";
                    }
                    else if (valor > 50000 && valor <= 125000)
                    {
                        venda = "Entre 50.001" +
                                " - 125.000 valores";
                        padrao = "Médio";
                    }
                    else if (valor > 125000 && valor <= 200000)
                    {
                        venda  = "Entre 125.001 - 200.000 valores";
                        padrao = "Classe A";
                    }

                    else
                    {
                        venda = "Acima de 200.001 valores";
                    }
                }
                padrao = "Alta Classe";
                #endregion

                #region Faixa Valor Aluguel
                //Verificando a faixa da area privada do imovel
                var aluguel  = Convert.ToDecimal(obj.valor_aluguel);
                var aluguelx = string.Empty;

                if (!String.IsNullOrEmpty(obj.valor_aluguel))
                {
                    if (aluguel > 0 && aluguel <= 1000)
                    {
                        aluguelx = "Entre 0 - 1.000 valores";
                    }
                    else if (aluguel > 1000 && aluguel <= 1500)
                    {
                        aluguelx = "Entre 1001" + " - 1.500 valores";
                    }
                    else if (aluguel > 1500 && aluguel <= 2750)
                    {
                        aluguelx = "Entre 1.501 - 2.750 valores";
                    }
                    else
                    {
                        aluguelx = "Acima de 2.751 valores";
                    }
                }
                #endregion



                #region Métodos de Validação --Snow Flake

                //Validando se Estado ja existe

                var uf    = br.BuscarEstado(obj.uf);
                var ufest = obj.uf;

                if (uf == 0)
                {
                    br.AdicionaEstado(ufest);
                }

                //Validando se Cidade ja existe

                var cid  = br.BuscaCidade(obj.cidade);
                var cida = obj.cidade;

                if (cid == 0)
                {
                    br.AdicionaCidade(obj.cidade, obj.uf);
                }

                //Validando se Bairro ja existe

                var bai  = br.BuscarBairro(obj.bairro);
                var bair = obj.bairro;
                var cep  = Convert.ToInt32(obj.cep.Substring(0, 5));

                if (bai == 0)
                {
                    br.AdicionaBairro(obj.cidade, bair, cep);
                }

                #endregion


                #region Métodos de Inserção

                #region Adicionando Imovel
                //Metodo para inserir Imovel no Banco
                var idImovel = banco.AdicionarImovel(obj.categoria != null ? obj.categoria : null,
                                                     obj.status != null ? obj.status : null,
                                                     areatot == "" ? null : areatot,
                                                     areapri == "" ? null : areapri,
                                                     fiptu == "" ? null : fiptu,
                                                     condo == "" ? null : condo,
                                                     obj.planta.Contains("SIM") ? true : false,
                                                     obj.dependencia.Contains("SIM") ? true : false,
                                                     obj.sacada.Contains("SIM") ? true : false,
                                                     obj.portaria.Contains("SIM") ? true : false,
                                                     obj.elevador.Contains("SIM") ? true : false,
                                                     obj.churrasqueira != null ? obj.churrasqueira : null,
                                                     torio == "" ? null : torio,
                                                     suites == "" ? null : suites,
                                                     carros == "" ? null : carros,
                                                     eirros == "" ? null : eirros,
                                                     venda == "" ? null : venda,
                                                     aluguelx == "" ? null : aluguelx,
                                                     obj.mostrar_mapa.Contains("SIM") ? true : false
                                                     );
                #endregion

                #region Tempo
                var ano = banco.RandomNumber();
                #endregion

                #region Fato

                banco.AdicionarFato(obj.bairro, ano, idImovel, padrao);

                #endregion

                #endregion
            }
        }
        static void Main(string[] args)
        {
            Banco banco = new Banco();

            var json = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"Imovel.json");

            var modelo = JsonConvert.DeserializeObject <List <Json> >(json);

            foreach (var obj in modelo.ToList())
            {
                //Verificando a faixa de preço do IPTU do imovel
                #region Faixa IPTU
                var iptu  = Convert.ToDecimal(obj.iptu);
                var fiptu = string.Empty;

                if (!String.IsNullOrEmpty(obj.iptu))
                {
                    if (iptu > 0 && iptu <= 600)
                    {
                        fiptu = "Entre 0 - 600 valores";
                    }
                    else if (iptu > 600 && iptu <= 1200)
                    {
                        fiptu = "Entre 601 - 1200 valores";
                    }
                    else if (iptu > 1200 && iptu <= 1800)
                    {
                        fiptu = "Entre 1201 - 1800 valores";
                    }
                    else
                    {
                        fiptu = "Acima de 1801 valores";
                    }
                }

                #endregion

                //Verificando a faixa de condominio do imovel
                #region Faixa Condominio
                var condominio  = Convert.ToDecimal(obj.condominio);
                var fcondominio = string.Empty;

                if (!String.IsNullOrEmpty(obj.condominio))
                {
                    if (condominio > 0 && condominio <= 100)
                    {
                        fcondominio = "Entre 0 - 100 metros";
                    }
                    else if (condominio > 100 && condominio <= 150)
                    {
                        fcondominio = "Entre 101 - 150 metros";
                    }
                    else if (condominio > 151 && condominio <= 200)
                    {
                        fcondominio = "Entre 151 - 200 metros";
                    }
                    else
                    {
                        fcondominio = "Acima de 201 metros";
                    }
                }
                #endregion

                //Verificando a faixa de dormitorios do imovel
                #region Faixa Dormitorios
                var dormitorio  = Convert.ToInt32(obj.dormitorios);
                var fdormitorio = string.Empty;

                if (!String.IsNullOrEmpty(obj.dormitorios))
                {
                    if (dormitorio > 0 && dormitorio <= 2)
                    {
                        fdormitorio = "Entre 0 - 2 dormitorios";
                    }
                    else if (dormitorio > 2 && dormitorio <= 4)
                    {
                        fdormitorio = "Entre 3 - 4" +
                                      " dormitorios";
                    }
                    else
                    {
                        fdormitorio = "Acima de 5 dormitorios";
                    }
                }
                #endregion

                //Verificando a faixa de suites do imovel
                #region Faixa Suites
                var suites  = Convert.ToInt32(obj.suites);
                var fsuites = string.Empty;

                if (!String.IsNullOrEmpty(obj.suites))
                {
                    if (suites > 0 && suites <= 2)
                    {
                        fsuites = "Entre 0 - 2 suites";
                    }
                    else if (suites > 2 && suites <= 4)
                    {
                        fsuites = "Entre 3 - 4 suites";
                    }
                    else
                    {
                        fsuites = "Acima de 5 suites";
                    }
                }
                #endregion

                //Verificando a faixa de vagas do imovel
                #region Faixa Vagas
                var vagas  = Convert.ToInt32(obj.vagas);
                var fvagas = string.Empty;

                if (!String.IsNullOrEmpty(obj.vagas))
                {
                    if (vagas > 0 && vagas <= 2)
                    {
                        fvagas = "Entre 0 - 2 vagas";
                    }
                    else if (vagas > 2 && vagas <= 4)
                    {
                        fvagas = "Entre 3 - 4 vagas";
                    }
                    else
                    {
                        fvagas = "Acima de 5 vagas";
                    }
                }
                #endregion

                //Verificando a faixa de banheiros do imovel
                #region Faixa Banheiros
                var banheiros  = Convert.ToInt32(obj.banheiros);
                var fbanheiros = string.Empty;

                if (!String.IsNullOrEmpty(obj.banheiros))
                {
                    if (banheiros > 0 && banheiros <= 2)
                    {
                        fbanheiros = "Entre 0 - 2 banheiros";
                    }
                    else if (banheiros > 2 && banheiros <= 4)
                    {
                        fbanheiros = "Entre 3 - 4 banheiros";
                    }
                    else
                    {
                        fbanheiros = "Acima de 5 banheiros";
                    }
                }
                #endregion

                //Verificando a faixa do valor de venda do imovel
                #region Faixa Venda
                var venda  = Convert.ToDecimal(obj.valor_venda);
                var fvenda = string.Empty;

                if (!String.IsNullOrEmpty(obj.valor_venda))
                {
                    if (venda > 0 && venda <= 50000)
                    {
                        fvenda = "Entre 0 - 50.000 valores";
                    }
                    else if (venda > 50000 && venda <= 125000)
                    {
                        fvenda = "Entre 50.001" +
                                 " - 125.000 valores";
                    }
                    else if (venda > 125000 && venda <= 200000)
                    {
                        fvenda = "Entre 125.001 - 200.000 valores";
                    }
                    else
                    {
                        fvenda = "Acima de 200.001 valores";
                    }
                }
                #endregion

                //Verificando a faixa da area privada do imovel
                #region Faixa Aluguel
                var aluguel  = Convert.ToDecimal(obj.valor_aluguel);
                var faluguel = string.Empty;

                if (!String.IsNullOrEmpty(obj.valor_aluguel))
                {
                    if (aluguel > 0 && aluguel <= 1000)
                    {
                        faluguel = "Entre 0 - 1.000 valores";
                    }
                    else if (aluguel > 1000 && aluguel <= 1500)
                    {
                        faluguel = "Entre 1001" + " - 1.500 valores";
                    }
                    else if (aluguel > 1500 && aluguel <= 2750)
                    {
                        faluguel = "Entre 1.501 - 2.750 valores";
                    }
                    else
                    {
                        faluguel = "Acima de 2.751 valores";
                    }
                }
                #endregion


                // Verificação
                #region
                var uf  = banco.BuscarEstado(obj.uf);
                var fuf = obj.uf;

                if (uf == 0)
                {
                    banco.AdicionaEstado(fuf);
                }

                //Verificando se Cidade ja existe

                var cidade  = banco.BuscaCidade(obj.cidade);
                var fcidade = obj.cidade;

                if (cidade == 0)
                {
                    banco.AdicionaCidade(obj.cidade, obj.uf);
                }

                //Verificando se Bairro ja existe

                var bairro  = banco.BuscarBairro(obj.bairro);
                var fbairro = obj.bairro;
                var cep     = Convert.ToInt32(obj.cep.Substring(0, 5));

                if (bairro == 0)
                {
                    banco.AdicionaBairro(obj.cidade, fbairro, cep);
                }

                #endregion


                //Metodo para inserir Imovel no Banco
                #region Adicionando Imovel
                var id_imovel = banco.AdicionarImovel(obj.categoria != null ? obj.categoria : null,
                                                      obj.status != null ? obj.status : null,
                                                      fiptu == "" ? null : fiptu,
                                                      fcondominio == "" ? null : fcondominio,
                                                      obj.planta.Contains("SIM") ? true : false,
                                                      obj.dependencia.Contains("SIM") ? true : false,
                                                      obj.sacada.Contains("SIM") ? true : false,
                                                      obj.portaria.Contains("SIM") ? true : false,
                                                      obj.elevador.Contains("SIM") ? true : false,
                                                      obj.churrasqueira != null ? obj.churrasqueira : null,
                                                      fdormitorio == "" ? null : fdormitorio,
                                                      fsuites == "" ? null : fsuites,
                                                      fvagas == "" ? null : fvagas,
                                                      fbanheiros == "" ? null : fbanheiros,
                                                      fvenda == "" ? null : fvenda,
                                                      faluguel == "" ? null : faluguel,
                                                      obj.bairro == "" ? null : obj.bairro
                                                      );
                #endregion

                // Método para inserir a Construcao no Banco
                #region Adicionando Construcao
                banco.AdicionarConstrucao(id_imovel);
                #endregion
            }
        }