Beispiel #1
0
        /// <summary>
        /// Altera os dados do endereço
        /// </summary>
        /// <param name="pEndereco"></param>
        public void AlterarDadosEndereco(Entidades.Nutricionista.Endereco pEndereco)
        {
            if (pEndereco == null)
            {
                throw new ArgumentException("O endereço é obrigatório.");
            }
            if (pEndereco.IdEndereco == 0)
            {
                throw new ArgumentException("O id do endereço é obrigatório.");
            }
            if (pEndereco.IdUsuario == 0)
            {
                throw new ArgumentException("O id do usuário logado é obrigatório.");
            }

            if (string.IsNullOrEmpty(pEndereco.CEP))
            {
                throw new ArgumentException("O CEP não pode ser nulo.");
            }

            Address endereco = new Correios.NET.Services().GetAddresses(pEndereco.CEP.Replace("-", "")).FirstOrDefault();

            if (endereco == null)
            {
                throw new Exception("CEP não localizado.");
            }
            if (!endereco.Street.Equals(pEndereco.Logradouro))
            {
                throw new Exception("Logradouro não corresponde com a cidade informada pelo CEP");
            }
            if (!endereco.District.Equals(pEndereco.Bairro))
            {
                throw new Exception("Cidade não corresponde com a cidade informada pelo CEP");
            }
            if (!endereco.City.Equals(pEndereco.Cidade))
            {
                throw new Exception("Cidade não corresponde com a cidade informada pelo CEP");
            }
            if (!Enum.GetValues(typeof(UnidadeFederacaoEnum))
                .Cast <UnidadeFederacaoEnum>()
                .FirstOrDefault(c => c.GetDefaultValue().Equals(endereco.State)).GetDefaultValue().Equals(pEndereco.UF.GetDefaultValue()))
            {
                throw new Exception("UF não corresponde com a cidade informada pelo CEP");
            }

            _EnderecoRepository.AlterarDadosEndereco(pEndereco);
        }
Beispiel #2
0
        /// <summary>
        /// Altera os dados do endereço
        /// </summary>
        /// <param name="pEndereco"></param>
        public void AlterarDadosEndereco(Entidades.Nutricionista.Endereco pEndereco)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("DECLARE @ID_ENDERECO INT,");
            stringBuilder.AppendLine("	@ID_USUARIO INT,");
            stringBuilder.AppendLine("  @NUMERO INT = NULL,");
            stringBuilder.AppendLine("	@RUA VARCHAR(100),");
            stringBuilder.AppendLine("	@COMPLEMENTO VARCHAR(255),");
            stringBuilder.AppendLine("	@BAIRRO VARCHAR(50),");
            stringBuilder.AppendLine("	@CIDADE VARCHAR(30),");
            stringBuilder.AppendLine("	@ESTADO VARCHAR(2),");
            stringBuilder.AppendLine("	@CEP VARCHAR(9)");
            stringBuilder.AppendLine($"SET @ID_ENDERECO = {pEndereco.IdEndereco}");
            stringBuilder.AppendLine($"SET @ID_USUARIO = {pEndereco.IdUsuario}");
            stringBuilder.AppendLine($"SET @NUMERO = {(pEndereco?.Numero == null ? "NULL" : pEndereco.Numero.ToString())}");
            stringBuilder.AppendLine($"SET @RUA = '{pEndereco.Logradouro}'");
            stringBuilder.AppendLine($"SET @COMPLEMENTO = '{pEndereco.Complemento}'");
            stringBuilder.AppendLine($"SET @BAIRRO = '{pEndereco.Bairro}'");
            stringBuilder.AppendLine($"SET @CIDADE = '{pEndereco.Cidade}'");
            stringBuilder.AppendLine($"SET @ESTADO = '{pEndereco.UF.GetDefaultValue()}'");
            stringBuilder.AppendLine($"SET @CEP = '{pEndereco.CEP}'");
            stringBuilder.AppendLine("UPDATE ENDERECO_TB");
            stringBuilder.AppendLine("    SET RUA = @RUA,");
            stringBuilder.AppendLine("    COMPLEMENTO = @COMPLEMENTO,");
            stringBuilder.AppendLine("    NUMERO = @NUMERO,");
            stringBuilder.AppendLine("    BAIRRO = @BAIRRO,");
            stringBuilder.AppendLine("    CIDADE = @CIDADE,");
            stringBuilder.AppendLine("    ESTADO = @ESTADO,");
            stringBuilder.AppendLine("    CEP = @CEP");
            stringBuilder.AppendLine("WHERE");
            stringBuilder.AppendLine("    ID_ENDERECO = @ID_ENDERECO");
            stringBuilder.AppendLine("    AND ID_USUARIO = @ID_USUARIO");
            stringBuilder.AppendLine("    AND EXISTS(SELECT TOP 1 1 FROM USUARIO_TB TB WITH(NOLOCK)");
            stringBuilder.AppendLine("        WHERE TB.ID_USUARIO = @ID_USUARIO");
            stringBuilder.AppendLine("        AND TB.TP_USUARIO = 1)");

            _UnitOfWork.Executar(stringBuilder.ToString());
        }
        /// <summary>
        /// Busca um contrato pelo seu número
        /// </summary>
        /// <param name="pID">Número do contrato</param>
        /// <returns>Contrato ou null</returns>
        public Entidades.Contrato.Contrato BuscaContratoPorID(int pID)
        {
            #region Query
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.AppendLine("DECLARE @ID_CONTRATO INT");
            stringBuilder.AppendLine($"SET @ID_CONTRATO = {pID}");
            stringBuilder.AppendLine("SELECT");
            stringBuilder.AppendLine("  C.ID_CONTRATO,");
            stringBuilder.AppendLine("	C.ID_USUARIO,");
            stringBuilder.AppendLine("	C.ID_NUTRI,");
            stringBuilder.AppendLine("	C.RUA,");
            stringBuilder.AppendLine("	C.COMPLEMENTO,");
            stringBuilder.AppendLine("	C.NUMERO,");
            stringBuilder.AppendLine("	C.BAIRRO,");
            stringBuilder.AppendLine("  C.CIDADE,");
            stringBuilder.AppendLine("	C.ESTADO,");
            stringBuilder.AppendLine("	C.CEP,");
            stringBuilder.AppendLine("	C.DT_INICIO,");
            stringBuilder.AppendLine("	C.DT_FIM,");
            stringBuilder.AppendLine("	C.STATUS,");
            stringBuilder.AppendLine("	C.DT_CADASTRO,");
            stringBuilder.AppendLine("	C.MENSAGEM");
            stringBuilder.AppendLine("FROM CONTRATO_TB C WITH(NOLOCK)");
            stringBuilder.AppendLine("WHERE");
            stringBuilder.AppendLine("    ID_CONTRATO = @ID_CONTRATO");

            #endregion
            List <Entidades.Contrato.Contrato> listaContratos = new List <Entidades.Contrato.Contrato>();

            DataSet ds = _UnitOfWork.Consulta(stringBuilder.ToString());

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                string Rua         = string.Empty,
                       Bairro      = string.Empty,
                       Cidade      = string.Empty,
                       CEP         = string.Empty,
                       Complemento = string.Empty,
                       Mensagem    = string.Empty;

                uint?Numero = null;
                int  idPaciente = 0, idNutricionista = 0, idContrato = 0;

                DateTime datainicio   = DateTime.MinValue,
                         dataFim      = DateTime.MinValue,
                         dataCadastro = DateTime.MinValue;

                UnidadeFederacaoEnum UF             = UnidadeFederacaoEnum.NaoDefinido;
                StatusContratoEnum   statusContrato = StatusContratoEnum.Agendada;

                if (ds.Tables[0].Rows[0]["ID_CONTRATO"] != DBNull.Value)
                {
                    idContrato = Convert.ToInt32(ds.Tables[0].Rows[0]["ID_CONTRATO"]);
                }
                if (ds.Tables[0].Rows[0]["ID_USUARIO"] != DBNull.Value)
                {
                    idPaciente = Convert.ToInt32(ds.Tables[0].Rows[0]["ID_USUARIO"]);
                }
                if (ds.Tables[0].Rows[0]["ID_NUTRI"] != DBNull.Value)
                {
                    idNutricionista = Convert.ToInt32(ds.Tables[0].Rows[0]["ID_NUTRI"]);
                }
                if (ds.Tables[0].Rows[0]["RUA"] != DBNull.Value)
                {
                    Rua = ds.Tables[0].Rows[0]["RUA"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BAIRRO"] != DBNull.Value)
                {
                    Bairro = ds.Tables[0].Rows[0]["BAIRRO"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CIDADE"] != DBNull.Value)
                {
                    Cidade = ds.Tables[0].Rows[0]["CIDADE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CEP"] != DBNull.Value)
                {
                    CEP = ds.Tables[0].Rows[0]["CEP"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CEP"] != DBNull.Value)
                {
                    CEP = ds.Tables[0].Rows[0]["CEP"].ToString();
                }
                if (ds.Tables[0].Rows[0]["COMPLEMENTO"] != DBNull.Value)
                {
                    Complemento = ds.Tables[0].Rows[0]["COMPLEMENTO"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NUMERO"] != DBNull.Value)
                {
                    Numero = Convert.ToUInt32(ds.Tables[0].Rows[0]["NUMERO"]);
                }
                if (ds.Tables[0].Rows[0]["ESTADO"] != DBNull.Value)
                {
                    UF = Enum.GetValues(typeof(UnidadeFederacaoEnum)).Cast <UnidadeFederacaoEnum>().
                         FirstOrDefault(s => s.GetDefaultValue().Equals(ds.Tables[0].Rows[0]["ESTADO"].ToString(), StringComparison.CurrentCultureIgnoreCase));
                }

                Entidades.Nutricionista.Endereco endereco = new Entidades.Nutricionista.Endereco(
                    idNutricionista,
                    Rua,
                    Bairro,
                    Cidade,
                    CEP,
                    UF
                    )
                {
                    Complemento = Complemento,
                    Numero      = Numero,
                };

                if (ds.Tables[0].Rows[0]["DT_INICIO"] != DBNull.Value)
                {
                    datainicio = Convert.ToDateTime(ds.Tables[0].Rows[0]["DT_INICIO"]);
                }
                if (ds.Tables[0].Rows[0]["DT_FIM"] != DBNull.Value)
                {
                    dataFim = Convert.ToDateTime(ds.Tables[0].Rows[0]["DT_FIM"]);
                }
                if (ds.Tables[0].Rows[0]["DT_CADASTRO"] != DBNull.Value)
                {
                    dataCadastro = Convert.ToDateTime(ds.Tables[0].Rows[0]["DT_CADASTRO"]);
                }

                if (ds.Tables[0].Rows[0]["STATUS"] != DBNull.Value)
                {
                    statusContrato = Enum.GetValues(typeof(StatusContratoEnum)).Cast <StatusContratoEnum>().
                                     FirstOrDefault(s => s.GetDefaultValue().Equals(ds.Tables[0].Rows[0]["STATUS"].ToString()));
                }

                if (ds.Tables[0].Rows[0]["MENSAGEM"] != DBNull.Value)
                {
                    Mensagem = ds.Tables[0].Rows[0]["MENSAGEM"].ToString();
                }

                return(new Entidades.Contrato.Contrato(
                           idPaciente,
                           idNutricionista,
                           endereco.Logradouro,
                           endereco?.Complemento,
                           endereco?.Numero,
                           endereco.Bairro,
                           endereco.Cidade,
                           endereco.UF,
                           endereco.CEP,
                           datainicio,
                           dataFim,
                           statusContrato
                           )
                {
                    IdContrato = idContrato,
                    DataCadastro = dataCadastro,
                    Mensagem = Mensagem
                });
            }

            return(null);
        }
        /// <summary>
        /// <summary>
        /// Lista os constratos de algum usuário
        /// </summary>
        /// <param name="pIndiceInicial">Indice inicial</param>
        /// <param name="pRua">Rua</param>
        /// <param name="pCidade">Cidade</param>
        /// <param name="pBairro">Bairro</param>
        /// <param name="pCEP">CEP</param>
        /// <param name="pUF">UF</param>
        /// <param name="pDataInicio">Data de início</param>
        /// <param name="pDataFim">Data fim</param>
        /// <param name="pIdUsuario">ID do usuário</param>
        /// <returns>Lista de contratos</returns>
        public List <Entidades.Contrato.Contrato> ListaContratos(string pRua, string pCidade, string pBairro, string pCEP, string pUF, DateTime pDataInicio, DateTime pDataFim, int pIdUsuario)
        {
            #region Query
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.AppendLine("DECLARE @RUA VARCHAR(100),");
            stringBuilder.AppendLine("	@CIDADE VARCHAR(30),");
            stringBuilder.AppendLine("	@BAIRRO VARCHAR(50),");
            stringBuilder.AppendLine("	@CEP VARCHAR(9),");
            stringBuilder.AppendLine("	@ESTADO VARCHAR(2),");
            stringBuilder.AppendLine("	@DT_INICIO DATETIME,");
            stringBuilder.AppendLine("  @DT_FIM DATETIME,");
            stringBuilder.AppendLine("	@ID_USUARIO INT");
            stringBuilder.AppendLine($"SET @ID_USUARIO = {pIdUsuario}");
            stringBuilder.AppendLine($"SET @RUA = '{pRua}'");
            stringBuilder.AppendLine($"SET @BAIRRO = '{pBairro}'");
            stringBuilder.AppendLine($"SET @CIDADE = '{pCidade}'");
            stringBuilder.AppendLine($"SET @CEP = {(string.IsNullOrEmpty(pCEP) ? "NULL" : "'" + pCEP + "'")}");
            stringBuilder.AppendLine($"SET @ESTADO = {(string.IsNullOrEmpty(pUF) ? "NULL" : "'" + Enum.GetValues(typeof(UnidadeFederacaoEnum)).Cast<UnidadeFederacaoEnum>().FirstOrDefault(c => c.GetDescription().Equals(pUF)).GetDefaultValue() + "'")}");
            stringBuilder.AppendLine($"SET @DT_INICIO = {(pDataInicio == DateTime.MinValue ? "NULL" : "'" + pDataInicio.ToString(Constantes.MascaraDataHoraSegundoSql) + "'")}");
            stringBuilder.AppendLine($"SET @DT_FIM = {(pDataFim == DateTime.MinValue ? "NULL" : "'" + pDataFim.ToString(Constantes.MascaraDataHoraSegundoSql) + "'")}");
            stringBuilder.AppendLine("SELECT");
            stringBuilder.AppendLine("  C.ID_CONTRATO,");
            stringBuilder.AppendLine("	C.ID_USUARIO,");
            stringBuilder.AppendLine("	C.ID_NUTRI,");
            stringBuilder.AppendLine("	C.RUA,");
            stringBuilder.AppendLine("	C.COMPLEMENTO,");
            stringBuilder.AppendLine("	C.NUMERO,");
            stringBuilder.AppendLine("	C.BAIRRO,");
            stringBuilder.AppendLine("  C.CIDADE,");
            stringBuilder.AppendLine("	C.ESTADO,");
            stringBuilder.AppendLine("	C.CEP,");
            stringBuilder.AppendLine("	C.DT_INICIO,");
            stringBuilder.AppendLine("	C.DT_FIM,");
            stringBuilder.AppendLine("	C.STATUS,");
            stringBuilder.AppendLine("	C.DT_CADASTRO,");
            stringBuilder.AppendLine("	C.MENSAGEM");
            stringBuilder.AppendLine("FROM CONTRATO_TB C WITH(NOLOCK)");
            stringBuilder.AppendLine("WHERE");
            stringBuilder.AppendLine("    (ISNULL(@RUA, C.RUA) = C.RUA OR C.RUA LIKE @RUA + '%')");
            stringBuilder.AppendLine("    AND(ISNULL(@CIDADE, C.CIDADE) = C.CIDADE OR C.CIDADE LIKE @CIDADE + '%')");
            stringBuilder.AppendLine("    AND(ISNULL(@BAIRRO, C.BAIRRO) = C.BAIRRO OR C.BAIRRO LIKE @BAIRRO + '%')");
            stringBuilder.AppendLine("    AND ISNULL(@CEP, C.CEP) = C.CEP");
            stringBuilder.AppendLine("    AND ISNULL(@ESTADO, C.ESTADO) = C.ESTADO");
            stringBuilder.AppendLine("    AND(C.DT_INICIO BETWEEN ISNULL(@DT_INICIO, C.DT_INICIO) AND ISNULL(@DT_FIM, C.DT_FIM)");
            stringBuilder.AppendLine("        OR C.DT_FIM BETWEEN ISNULL(@DT_INICIO, C.DT_INICIO) AND ISNULL(@DT_FIM, C.DT_FIM)");
            stringBuilder.AppendLine("    )");
            stringBuilder.AppendLine("    AND(C.ID_NUTRI = @ID_USUARIO OR C.ID_USUARIO = @ID_USUARIO)");

            #endregion
            List <Entidades.Contrato.Contrato> listaContratos = new List <Entidades.Contrato.Contrato>();

            DataSet ds = _UnitOfWork.Consulta(stringBuilder.ToString());

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DateTime datainicio   = DateTime.MinValue,
                             dataFim      = DateTime.MinValue,
                             dataCadastro = DateTime.MinValue;

                    string Rua         = string.Empty,
                           Bairro      = string.Empty,
                           Cidade      = string.Empty,
                           CEP         = string.Empty,
                           Complemento = string.Empty,
                           Mensagem    = string.Empty;

                    uint?Numero = null;
                    int  idPaciente = 0, idNutricionista = 0, idContrato = 0;

                    UnidadeFederacaoEnum UF             = UnidadeFederacaoEnum.NaoDefinido;
                    StatusContratoEnum   statusContrato = StatusContratoEnum.Agendada;

                    if (ds.Tables[0].Rows[i]["RUA"] != DBNull.Value)
                    {
                        Rua = ds.Tables[0].Rows[i]["RUA"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["BAIRRO"] != DBNull.Value)
                    {
                        Bairro = ds.Tables[0].Rows[i]["BAIRRO"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["CIDADE"] != DBNull.Value)
                    {
                        Cidade = ds.Tables[0].Rows[i]["CIDADE"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["CEP"] != DBNull.Value)
                    {
                        CEP = ds.Tables[0].Rows[i]["CEP"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["CEP"] != DBNull.Value)
                    {
                        CEP = ds.Tables[0].Rows[i]["CEP"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["COMPLEMENTO"] != DBNull.Value)
                    {
                        Complemento = ds.Tables[0].Rows[i]["COMPLEMENTO"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["NUMERO"] != DBNull.Value)
                    {
                        Numero = Convert.ToUInt32(ds.Tables[0].Rows[i]["NUMERO"]);
                    }
                    if (ds.Tables[0].Rows[i]["ESTADO"] != DBNull.Value)
                    {
                        UF = Enum.GetValues(typeof(UnidadeFederacaoEnum)).Cast <UnidadeFederacaoEnum>().
                             FirstOrDefault(s => s.GetDefaultValue().Equals(ds.Tables[0].Rows[i]["ESTADO"].ToString(), StringComparison.CurrentCultureIgnoreCase));
                    }

                    Entidades.Nutricionista.Endereco endereco = new Entidades.Nutricionista.Endereco(
                        pIdUsuario,
                        Rua,
                        Bairro,
                        Cidade,
                        CEP,
                        UF
                        )
                    {
                        Complemento = Complemento,
                        Numero      = Numero,
                    };

                    if (ds.Tables[0].Rows[i]["DT_INICIO"] != DBNull.Value)
                    {
                        datainicio = Convert.ToDateTime(ds.Tables[0].Rows[i]["DT_INICIO"]);
                    }
                    if (ds.Tables[0].Rows[i]["DT_FIM"] != DBNull.Value)
                    {
                        dataFim = Convert.ToDateTime(ds.Tables[0].Rows[i]["DT_FIM"]);
                    }
                    if (ds.Tables[0].Rows[i]["DT_CADASTRO"] != DBNull.Value)
                    {
                        dataCadastro = Convert.ToDateTime(ds.Tables[0].Rows[i]["DT_CADASTRO"]);
                    }

                    if (ds.Tables[0].Rows[i]["ID_CONTRATO"] != DBNull.Value)
                    {
                        idContrato = Convert.ToInt32(ds.Tables[0].Rows[i]["ID_CONTRATO"]);
                    }
                    if (ds.Tables[0].Rows[i]["ID_USUARIO"] != DBNull.Value)
                    {
                        idPaciente = Convert.ToInt32(ds.Tables[0].Rows[i]["ID_USUARIO"]);
                    }
                    if (ds.Tables[0].Rows[i]["ID_NUTRI"] != DBNull.Value)
                    {
                        idNutricionista = Convert.ToInt32(ds.Tables[0].Rows[i]["ID_NUTRI"]);
                    }
                    if (ds.Tables[0].Rows[i]["MENSAGEM"] != DBNull.Value)
                    {
                        Mensagem = ds.Tables[0].Rows[i]["MENSAGEM"].ToString();
                    }

                    if (ds.Tables[0].Rows[i]["STATUS"] != DBNull.Value)
                    {
                        statusContrato = Enum.GetValues(typeof(StatusContratoEnum)).Cast <StatusContratoEnum>().
                                         FirstOrDefault(s => s.GetDefaultValue().Equals(ds.Tables[0].Rows[i]["STATUS"].ToString()));
                    }

                    listaContratos.Add(new Entidades.Contrato.Contrato(
                                           idPaciente,
                                           idNutricionista,
                                           endereco.Logradouro,
                                           endereco?.Complemento,
                                           endereco?.Numero,
                                           endereco.Bairro,
                                           endereco.Cidade,
                                           endereco.UF,
                                           endereco.CEP,
                                           datainicio,
                                           dataFim,
                                           statusContrato
                                           )
                    {
                        IdContrato   = idContrato,
                        DataCadastro = dataCadastro,
                        Mensagem     = Mensagem
                    });
                }
            }

            return(listaContratos);
        }
Beispiel #5
0
        /// <summary>
        /// Lista os endereços cadastrados
        /// </summary>
        /// <param name="pIdUsuario">ID do usuário</param>
        /// <param name="pRua">Rua</param>
        /// <param name="pCidade">Cidade</param>
        /// <param name="pBairro">Bairro</param>
        /// <param name="pCEP">CEP</param>
        /// <param name="pUF">UF</param>
        /// <returns>Uma lista de endereços</returns>
        public List <Entidades.Nutricionista.Endereco> EnderecosCadastrados(int pIdUsuario, string pRua, string pCidade, string pBairro, string pCEP, string pUF)
        {
            StringBuilder stringBuilder = new StringBuilder();

            #region Select
            stringBuilder.AppendLine("DECLARE @ID_USUARIO INT,");
            stringBuilder.AppendLine("  @RUA VARCHAR(100),");
            stringBuilder.AppendLine("  @BAIRRO VARCHAR(50),");
            stringBuilder.AppendLine("  @CIDADE VARCHAR(30),");
            stringBuilder.AppendLine("  @CEP VARCHAR(9) = NULL,");
            stringBuilder.AppendLine("  @ESTADO VARCHAR(2) = NULL");
            stringBuilder.AppendLine($"SET @ID_USUARIO = {pIdUsuario}");
            stringBuilder.AppendLine($"SET @RUA = '{pRua}'");
            stringBuilder.AppendLine($"SET @BAIRRO = '{pBairro}'");
            stringBuilder.AppendLine($"SET @CIDADE = '{pCidade}'");
            stringBuilder.AppendLine($"SET @CEP = {(string.IsNullOrEmpty(pCEP) ? "NULL" : "'" + pCEP + "'")}");
            stringBuilder.AppendLine($"SET @ESTADO = {(string.IsNullOrEmpty(pUF) ? "NULL" : "'" + Enum.GetValues(typeof(UnidadeFederacaoEnum)).Cast<UnidadeFederacaoEnum>().FirstOrDefault(c => c.GetDescription().Equals(pUF)).GetDefaultValue() + "'")}");
            stringBuilder.AppendLine("SELECT");
            stringBuilder.AppendLine("  E.ID_ENDERECO,");
            stringBuilder.AppendLine("  E.RUA,");
            stringBuilder.AppendLine("	E.COMPLEMENTO,");
            stringBuilder.AppendLine("	E.NUMERO,");
            stringBuilder.AppendLine("	E.BAIRRO,");
            stringBuilder.AppendLine("	E.CIDADE,");
            stringBuilder.AppendLine("	E.ESTADO,");
            stringBuilder.AppendLine("	E.CEP");
            stringBuilder.AppendLine("FROM ENDERECO_TB E WITH(NOLOCK)");
            stringBuilder.AppendLine("    INNER JOIN USUARIO_TB U WITH(NOLOCK) ON U.ID_USUARIO = E.ID_USUARIO");
            stringBuilder.AppendLine("        AND U.TP_USUARIO = 1");
            stringBuilder.AppendLine("WHERE(ISNULL(@RUA, E.RUA) = E.RUA OR E.RUA LIKE @RUA + '%')");
            stringBuilder.AppendLine("    AND(ISNULL(@BAIRRO, E.BAIRRO) = E.BAIRRO OR E.BAIRRO LIKE @BAIRRO + '%')");
            stringBuilder.AppendLine("    AND(ISNULL(@CIDADE, E.CIDADE) = E.CIDADE OR E.CIDADE LIKE @CIDADE + '%')");
            stringBuilder.AppendLine("    AND ISNULL(@ESTADO, E.ESTADO) = E.ESTADO");
            stringBuilder.AppendLine("    AND ISNULL(@CEP, E.CEP) = E.CEP");
            stringBuilder.AppendLine("    AND @ID_USUARIO = E.ID_USUARIO");
            #endregion

            DataSet ds = _UnitOfWork.Consulta(stringBuilder.ToString());
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                List <Entidades.Nutricionista.Endereco> enderecos = new List <Entidades.Nutricionista.Endereco>();

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    int    idEndereco  = 0;
                    string Rua         = string.Empty,
                           Bairro      = string.Empty,
                           Cidade      = string.Empty,
                           CEP         = string.Empty,
                           Complemento = string.Empty;

                    uint?Numero = null;

                    UnidadeFederacaoEnum UF = UnidadeFederacaoEnum.NaoDefinido;

                    if (ds.Tables[0].Rows[i]["ID_ENDERECO"] != DBNull.Value)
                    {
                        idEndereco = Convert.ToInt32(ds.Tables[0].Rows[i]["ID_ENDERECO"].ToString());
                    }
                    if (ds.Tables[0].Rows[i]["RUA"] != DBNull.Value)
                    {
                        Rua = ds.Tables[0].Rows[i]["RUA"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["BAIRRO"] != DBNull.Value)
                    {
                        Bairro = ds.Tables[0].Rows[i]["BAIRRO"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["CIDADE"] != DBNull.Value)
                    {
                        Cidade = ds.Tables[0].Rows[i]["CIDADE"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["CEP"] != DBNull.Value)
                    {
                        CEP = ds.Tables[0].Rows[i]["CEP"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["CEP"] != DBNull.Value)
                    {
                        CEP = ds.Tables[0].Rows[i]["CEP"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["COMPLEMENTO"] != DBNull.Value)
                    {
                        Complemento = ds.Tables[0].Rows[i]["COMPLEMENTO"].ToString();
                    }
                    if (ds.Tables[0].Rows[i]["NUMERO"] != DBNull.Value)
                    {
                        Numero = Convert.ToUInt32(ds.Tables[0].Rows[i]["NUMERO"]);
                    }
                    if (ds.Tables[0].Rows[i]["ESTADO"] != DBNull.Value)
                    {
                        UF = Enum.GetValues(typeof(UnidadeFederacaoEnum)).Cast <UnidadeFederacaoEnum>().
                             FirstOrDefault(s => s.GetDefaultValue().Equals(ds.Tables[0].Rows[i]["ESTADO"].ToString()));
                    }

                    Entidades.Nutricionista.Endereco endereco = new Entidades.Nutricionista.Endereco(
                        pIdUsuario,
                        Rua,
                        Bairro,
                        Cidade,
                        CEP,
                        UF
                        )
                    {
                        Complemento = Complemento,
                        Numero      = Numero,
                        IdEndereco  = idEndereco
                    };



                    enderecos.Add(endereco);
                }

                return(enderecos);
            }
            else
            {
                return(new List <Entidades.Nutricionista.Endereco>());
            }
        }
Beispiel #6
0
 /// <summary>
 /// Cadastra um endereço
 /// </summary>
 /// <param name="pEndereco">Endereço a ser cadastrado</param>
 public void CadastrarEndereco(Entidades.Nutricionista.Endereco pEndereco)
 {
     _UnitOfWork.Executar(
         _UnitOfWork.MontaInsertPorAttributo(pEndereco).ToString()
         );
 }
Beispiel #7
0
        /// <summary>
        /// Consulta o endereço do nutricionista pelo ID
        /// </summary>
        /// <param name="pID">ID do endereço</param>
        /// <param name="pIDUsuario">ID do usuário</param>
        /// <returns>Endereço ou null</returns>
        public Entidades.Nutricionista.Endereco ConsultarEnderecoNutricionistaPorID(int pID, int pIDUsuario)
        {
            StringBuilder stringBuilder = new StringBuilder();

            #region Select
            stringBuilder.AppendLine("DECLARE @ID_USUARIO INT,");
            stringBuilder.AppendLine("  @ID_ENDERECO INT");
            stringBuilder.AppendLine($"SET @ID_USUARIO = {pIDUsuario}");
            stringBuilder.AppendLine($"SET @ID_ENDERECO = {pID}");
            stringBuilder.AppendLine("SELECT");
            stringBuilder.AppendLine("  E.ID_ENDERECO,");
            stringBuilder.AppendLine("  E.RUA,");
            stringBuilder.AppendLine("	E.COMPLEMENTO,");
            stringBuilder.AppendLine("	E.NUMERO,");
            stringBuilder.AppendLine("	E.BAIRRO,");
            stringBuilder.AppendLine("	E.CIDADE,");
            stringBuilder.AppendLine("	E.ESTADO,");
            stringBuilder.AppendLine("	E.CEP");
            stringBuilder.AppendLine("FROM ENDERECO_TB E WITH(NOLOCK)");
            stringBuilder.AppendLine("    INNER JOIN USUARIO_TB U WITH(NOLOCK) ON U.ID_USUARIO = E.ID_USUARIO");
            stringBuilder.AppendLine("        AND U.TP_USUARIO = 1");
            stringBuilder.AppendLine("WHERE @ID_ENDERECO = E.ID_ENDERECO");
            stringBuilder.AppendLine("    AND @ID_USUARIO = E.ID_USUARIO");
            #endregion

            DataSet ds = _UnitOfWork.Consulta(stringBuilder.ToString());
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                int    idEndereco  = 0;
                string Rua         = string.Empty,
                       Bairro      = string.Empty,
                       Cidade      = string.Empty,
                       CEP         = string.Empty,
                       Complemento = string.Empty;

                uint?Numero = null;

                UnidadeFederacaoEnum UF = UnidadeFederacaoEnum.NaoDefinido;

                if (ds.Tables[0].Rows[0]["ID_ENDERECO"] != DBNull.Value)
                {
                    idEndereco = Convert.ToInt32(ds.Tables[0].Rows[0]["ID_ENDERECO"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RUA"] != DBNull.Value)
                {
                    Rua = ds.Tables[0].Rows[0]["RUA"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BAIRRO"] != DBNull.Value)
                {
                    Bairro = ds.Tables[0].Rows[0]["BAIRRO"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CIDADE"] != DBNull.Value)
                {
                    Cidade = ds.Tables[0].Rows[0]["CIDADE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CEP"] != DBNull.Value)
                {
                    CEP = ds.Tables[0].Rows[0]["CEP"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CEP"] != DBNull.Value)
                {
                    CEP = ds.Tables[0].Rows[0]["CEP"].ToString();
                }
                if (ds.Tables[0].Rows[0]["COMPLEMENTO"] != DBNull.Value)
                {
                    Complemento = ds.Tables[0].Rows[0]["COMPLEMENTO"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NUMERO"] != DBNull.Value)
                {
                    Numero = Convert.ToUInt32(ds.Tables[0].Rows[0]["NUMERO"]);
                }
                if (ds.Tables[0].Rows[0]["ESTADO"] != DBNull.Value)
                {
                    UF = Enum.GetValues(typeof(UnidadeFederacaoEnum)).Cast <UnidadeFederacaoEnum>().
                         FirstOrDefault(s => s.GetDefaultValue().Equals(ds.Tables[0].Rows[0]["ESTADO"].ToString()));
                }

                Entidades.Nutricionista.Endereco endereco = new Entidades.Nutricionista.Endereco(
                    pIDUsuario,
                    Rua,
                    Bairro,
                    Cidade,
                    CEP,
                    UF
                    )
                {
                    Complemento = Complemento,
                    Numero      = Numero,
                    IdEndereco  = idEndereco
                };
                return(endereco);
            }
            else
            {
                return(null);
            }
        }