コード例 #1
0
        public RetornoModel <Login, enumClienteException> GetLogado()
        {
            RetornoModel <Login, enumClienteException> retorno;

            using (var ado = new MasterADOBase())
            {
                ClienteBO clienteBO = new ClienteBO(SessionModel.GetSiteId());
                CarregarClienteOSESP(clienteBO, false);

                if (SessionModel.Login == null)
                {
                    retorno = new RetornoModel <Login, enumClienteException>()
                    {
                        Sucesso = false, Mensagem = "Não existe um cliente logado", Retorno = null, Tipo = enumClienteException.usuarioNaoEncontrado
                    };
                    NewRelicIgnoreTransaction();
                    throw new HttpResponseException(Request.CreateResponse((HttpStatusCode)422, ParseRetorno(retorno)));
                }
                else
                {
                    Login login = SessionModel.Login;
                    retorno         = new RetornoModel <Login, enumClienteException>();
                    retorno.Sucesso = true;
                    retorno.Retorno = login;
                }
            }
            return(ParseRetorno(retorno));
        }
コード例 #2
0
        public RetornoModel <Login, enumClienteException> PostAuth([FromBody] ClienteAuthRequestModel obj)
        {
            RetornoModel <Login, enumClienteException> retorno;

            if (obj != null && obj.username != null && obj.password != null)
            {
                using (ClienteBO clienteBO = new ClienteBO(SessionModel.GetSiteId()))
                {
                    try
                    {
                        retorno = clienteBO.LogarOsesp(obj.username, obj.password);
                    }
                    catch (Exception ex)
                    {
                        retorno          = new RetornoModel <Login, enumClienteException>();
                        retorno.Mensagem = ex.Message;
                        retorno.Sucesso  = false;
                        LogUtil.Error(ex);
                        throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, ParseRetorno(retorno)));
                    }

                    if (!retorno.Sucesso)
                    {
                        NewRelicIgnoreTransaction();
                        throw new HttpResponseException(Request.CreateResponse((HttpStatusCode)422, ParseRetorno(retorno)));
                    }
                    else
                    {
                        try
                        {
                            // Guarda o cliente logado na sessao
                            SessionModel.ClienteID = retorno.Retorno.ClienteID;
                            SessionModel.SiteID    = retorno.Retorno.SiteID;

                            return(ParseRetorno(retorno));
                        }
                        catch (Exception ex)
                        {
                            retorno          = new RetornoModel <Login, enumClienteException>();
                            retorno.Mensagem = ex.Message;
                            retorno.Sucesso  = false;
                            LogUtil.Error(ex);
                            throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, ParseRetorno(retorno)));
                        }
                    }
                }
            }
            else
            {
                retorno          = new RetornoModel <Login, enumClienteException>();
                retorno.Mensagem = "Objeto Auth não encontrado ou mal formatado";
                retorno.Sucesso  = false;
                NewRelicIgnoreTransaction();
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ParseRetorno(retorno)));
            }
        }
コード例 #3
0
        public RetornoModel <SessionModel> GetSessao(bool completo = false)
        {
            if (completo)
            {
                using (var ado = new MasterADOBase())
                {
                    var bo = new CompraBOModel(SessionModel.GetSiteId(), ado);
                    CarregarCompra(bo, true);
                }
            }
            RetornoModel <SessionModel> retorno = new RetornoModel <SessionModel>();

            retorno.Sucesso  = true;
            retorno.Mensagem = "OK";
            retorno.Retorno  = SessionModel;
            return(ParseRetorno(retorno));
        }
コード例 #4
0
        public RetornoModel <Login, enumClienteException> PutLogado([FromBody] Login obj)
        {
            RetornoModel <Login, enumClienteException> retorno;

            using (var ado = new MasterADOBase())
            {
                ClienteBO clienteBO = new ClienteBO(SessionModel.GetSiteId());
                CarregarClienteOSESP(clienteBO, false);
                if (obj != null)
                {
                    if (SessionModel.Login == null)
                    {
                        retorno = new RetornoModel <Login, enumClienteException>()
                        {
                            Sucesso = false, Mensagem = "Não existe um cliente logado", Retorno = null, Tipo = enumClienteException.usuarioNaoEncontrado
                        };
                        NewRelicIgnoreTransaction();
                        throw new HttpResponseException(Request.CreateResponse((HttpStatusCode)422, ParseRetorno(retorno)));
                    }
                    Login login = SessionModel.Login;
                    login.Email             = obj.Email;
                    login.FaceBookUserID    = login.FaceBookUserID;
                    login.FaceBookUserToken = login.FaceBookUserToken;
                    login.FaceBookUserInfos = login.FaceBookUserInfos;
                    login.CPF = obj.CPF.Replace(new string[] { ".", "-" }, "");

                    if (login.Cliente == null)
                    {
                        login.Cliente = new tCliente();
                    }

                    if (!string.IsNullOrEmpty(obj.Cliente.Senha))
                    {
                        login.Cliente.Senha = obj.Cliente.Senha;
                    }
                    login.Cliente.RG                   = obj.Cliente.RG;
                    login.Cliente.ContatoTipoID        = obj.Cliente.ContatoTipoID;
                    login.Cliente.Pais                 = obj.Cliente.Pais;
                    login.Cliente.Nome                 = obj.Cliente.Nome;
                    login.Cliente.DDDCelular           = obj.Cliente.DDDCelular;
                    login.Cliente.Celular              = obj.Cliente.Celular;
                    login.Cliente.DDDTelefone          = obj.Cliente.DDDTelefone;
                    login.Cliente.Telefone             = obj.Cliente.Telefone;
                    login.Cliente.DDDTelefoneComercial = obj.Cliente.DDDTelefoneComercial;
                    login.Cliente.TelefoneComercial    = obj.Cliente.DDDTelefoneComercial;
                    login.Cliente.RecebeEmailAsBool    = obj.Cliente.RecebeEmailAsBool;
                    login.Cliente.DataNascimento       = obj.Cliente.DataNascimento;
                    login.Cliente.Sexo                 = obj.Cliente.Sexo;
                    login.Cliente.CidadeCliente        = obj.Cliente.CidadeCliente;
                    login.Cliente.EstadoCliente        = obj.Cliente.EstadoCliente;
                    login.Cliente.EnderecoCliente      = obj.Cliente.EnderecoCliente;
                    login.Cliente.NumeroCliente        = obj.Cliente.NumeroCliente;
                    if (!string.IsNullOrEmpty(obj.Cliente.CEPCliente))
                    {
                        login.Cliente.CEPCliente = obj.Cliente.CEPCliente.Replace("-", "");
                    }
                    login.Cliente.ComplementoCliente = obj.Cliente.ComplementoCliente;
                    login.Cliente.BairroCliente      = obj.Cliente.BairroCliente;

                    login.Cliente.SituacaoProfissionalID = obj.Cliente.SituacaoProfissionalID;
                    login.Cliente.Profissao = obj.Cliente.Profissao;
                    login.Cliente.Email     = obj.Cliente.Email;
                    login.Cliente.Senha     = obj.Cliente.Senha;

                    bool salvarConcluido = false;
                    try
                    {
                        salvarConcluido = clienteBO.Salvar(login, SessionModel.UsuarioID);
                    }
                    catch (Exception ex)
                    {
                        retorno          = new RetornoModel <Login, enumClienteException>();
                        retorno.Mensagem = ex.Message;
                        retorno.Sucesso  = false;
                        LogUtil.Error(ex);
                        throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, ParseRetorno(retorno)));
                    }

                    if (salvarConcluido)
                    {
                        retorno          = new RetornoModel <Login, enumClienteException>();
                        retorno.Mensagem = "OK";
                        retorno.Retorno  = login;
                        retorno.Sucesso  = true;
                    }
                    else
                    {
                        retorno          = new RetornoModel <Login, enumClienteException>();
                        retorno.Mensagem = "Não foi possível completar a solicitação";
                        retorno.Sucesso  = false;
                        NewRelicIgnoreTransaction();
                        throw new HttpResponseException(Request.CreateResponse((HttpStatusCode)422, ParseRetorno(retorno)));
                    }
                    retorno.Sucesso = salvarConcluido;
                }
                else
                {
                    retorno          = new RetornoModel <Login, enumClienteException>();
                    retorno.Mensagem = "Objeto Login não encontrado";
                    retorno.Sucesso  = false;
                    NewRelicIgnoreTransaction();
                    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ParseRetorno(retorno)));
                }
            }
            return(ParseRetorno(retorno));
        }