コード例 #1
0
        public string abrirProduto(string dtoChave, string dtoProduto)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno = new DtoRetorno("ACK");
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                DtoProduto produto = js.Deserialize<DtoProduto>(dtoProduto);
                Produto mProduto = new Produto();
                produto = mProduto.abrirProduto(produto.id);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, produto);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: DtoProduto com DtoTipoProduto e DtoFabricante*/
            return js.Serialize(retorno);
        }
コード例 #2
0
        public string buscarItem(string dtoChave, string dtoProduto, string dtoEstabelecimento)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno = new DtoRetorno("ACK");
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoProduto produto = js.Deserialize<DtoProduto>(dtoProduto);
            DtoEnderecoEstabelecimento enderecoEstabelecimento = js.Deserialize<DtoEnderecoEstabelecimento>(dtoEstabelecimento);

            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Item mItem = new Item();
                DtoItem item = mItem.abrirItem(produto.id, enderecoEstabelecimento.id);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, item);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: DtoItem com DtoProduto com DtoTipoProduto e DtoFabricante*/
            return js.Serialize(retorno);
        }
コード例 #3
0
        //______________ LOGAR ________________//
        public string logar(string dtoUsuario)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoUsuario usuario = js.Deserialize<DtoUsuario>(dtoUsuario);
            Usuario mUsuario = new Usuario();
            DtoRetorno retorno;

            try
            {
                DtoChave chave = mUsuario.logar(usuario.email, usuario.senha);
                if(chave.token == "00000")
                {
                    retorno = new DtoRetornoObjeto(chave, "#/alterarSenha");
                }
                else
                {
                    retorno = new DtoRetornoObjeto(chave, "#/menu");
                }

            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            return js.Serialize(retorno);
        }
コード例 #4
0
        public string criarEstabelecimento(string dtoChave, string dtoEnderecoEstabelecimento)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoEnderecoEstabelecimento enderecoEstabelecimento = js.Deserialize<DtoEnderecoEstabelecimento>(dtoEnderecoEstabelecimento);
            DtoEnderecoEstabelecimento estabelecimento;

            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Estabelecimento mEstabelecimento = new Estabelecimento();
                estabelecimento = mEstabelecimento.cadastrarEstabelecimento(enderecoEstabelecimento);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, estabelecimento);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: DtoEnderecoEstabelecimento com DtoEstabelecimento*/
            return js.Serialize(retorno);
        }
コード例 #5
0
        /*Não Implementado*/
        public string adicionarProduto(string dtoChave, string dtoLista, string dtoProdutoDaLista)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoLista lista = js.Deserialize<DtoLista>(dtoLista);

            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                DtoProdutoDaLista produtoDaLista = js.Deserialize<DtoProdutoDaLista>(dtoProdutoDaLista);
                Lista mLista = new Lista();
                produtoDaLista = mLista.adicionarProduto(produtoDaLista);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, produtoDaLista);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: DtoProdutoDaLista com o DtoProduto*/
            return js.Serialize(retorno);
        }
コード例 #6
0
        public string abrirEstabelecimento(string dtoChave, string dtoEnderecoEstabelecimento)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoEnderecoEstabelecimento enderecoEstabelecimento = js.Deserialize<DtoEnderecoEstabelecimento>(dtoEnderecoEstabelecimento);
            DtoEnderecoEstabelecimento estabelecimento;

            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Estabelecimento mEstabelecimento = new Estabelecimento();
                estabelecimento = mEstabelecimento.abrirEstabelecimento(enderecoEstabelecimento.id);
                //estabelecimento.itens = mEstabelecimento.procurarProduto(estabelecimento, new DtoProduto());
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, estabelecimento);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: DtoEnderecoEstabelecimento com DtoEstabelecimento e Array de DtoItem com DtoProduto*/
            return js.Serialize(retorno);
        }
コード例 #7
0
        //______________ ALTERAR DADOS CADASTRAIS ________________//
        public string alterarDadosCadastrais(string senha, string novaSenha)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            Usuario mUsuario = new Usuario();
            DtoRetorno retorno;

            try
            {
                DtoChave chave = mUsuario.alterarDadosCadastrais(senha, novaSenha);
                retorno = new DtoRetornoObjeto(chave, "#/menu");
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            return js.Serialize(retorno);
        }
コード例 #8
0
ファイル: DtoExcecao.cs プロジェクト: jonnathanBruno/catalog
 public DtoRetornoErro ToDto()
 {
     DtoRetornoErro dto = new DtoRetornoErro(mensagem, codigoErro, destino);
     return dto;
 }
コード例 #9
0
        public string criarProduto(string dtoChave, string dtoProduto)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoProduto produto = js.Deserialize<DtoProduto>(dtoProduto);

            if (produto.nome.Length < 3 || produto.idTipo < 1)
            {
                retorno = (new DtoExcecao(DTO.Enum.CriteriosDeCadastroInsuficientes, "Nome do produto e Tipo do Produto")).ToDto();
                return js.Serialize(retorno);
            }

            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Produto mProduto = new Produto();
                produto = mProduto.cadastrarProduto(produto);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, produto);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: DtoProduto com DtoTipoProduto e DtoFabricante*/
            return js.Serialize(retorno);
        }
コード例 #10
0
        public string pesquisarProduto(string dtoChave, string parametros)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoProduto param = js.Deserialize<DtoProduto>(parametros);

            if (param.nome.Length < 3 &&
                param.tipoCodigoDeBarras.Length < 3 &&
                (param.tipo == null || param.tipo.tipo.Length < 3) &&
                (param.fabricante == null || param.fabricante.fabricante.Length < 3))
            {
                retorno = (new DtoExcecao(DTO.Enum.CriteriosDeBuscaInsuficientes)).ToDto();
                return js.Serialize(retorno);
            }

            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Produto mProduto = new Produto();
                DtoProduto[] produtos = mProduto.pesquisarProduto(param);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, produtos);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: Array de DtoProdutos com DtoTipoProduto e DtoFabricante*/
            return js.Serialize(retorno);
        }
コード例 #11
0
        public string pesquisarLista(string dtoChave)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoLista[] listas;

            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Lista mLista = new Lista();
                listas = mLista.pesquisarListas(chave.idUsuario);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, listas);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: Array de DtoLista*/
            return js.Serialize(retorno);
        }
コード例 #12
0
        //______________ RECUPERAR SENHA ________________//
        public string recuperarSenha(string dtoUsuario)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoUsuario usuario = js.Deserialize<DtoUsuario>(dtoUsuario);
            DtoRetorno retorno;

            try
            {
                Usuario mUsuario = new Usuario();
                mUsuario.recuperarSenha(usuario.email);
                retorno = new DtoRetorno("ACK","");
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            return js.Serialize(retorno);
        }
コード例 #13
0
        public string criarLista(string dtoChave, string dtoLista)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoLista lista = js.Deserialize<DtoLista>(dtoLista);

            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Lista mLista = new Lista();
                lista.idUsuario = chave.idUsuario;
                lista = mLista.criarLista(lista);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, lista);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: DtoLista puro*/
            return js.Serialize(retorno);
        }
コード例 #14
0
        public string removerProduto(string dtoChave, string dtoLista, string dtoProduto)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoProdutoDaLista produtoDaLista = js.Deserialize<DtoProdutoDaLista>(dtoProduto);

            try
            {
                Chave mChave = new Chave();
                mChave.validarChave(chave);
                Lista mLista = new Lista();
                mLista.removerProduto(produtoDaLista.id);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: apenas a chave*/
            return js.Serialize(retorno);
        }
コード例 #15
0
        //_____________ REALIZAR CADASTRO _____________//
        public string realizarCadastro(string dtoUsuario)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoUsuario usuario = js.Deserialize<DtoUsuario>(dtoUsuario);
            Usuario mUsuario = new Usuario();
            DtoRetorno retorno;
            Regex rg = new Regex(@"^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");

            //---validando nome, email, senha
            if(
              (usuario.nome.Length >= 3) &&
              (rg.IsMatch(usuario.email)) &&
              (usuario.senha.Length >3)  )
            {
                try
                {
                    DtoChave chave = mUsuario.cadastrarUsuario(usuario);
                    retorno = new DtoRetornoObjeto(chave,"#/menu");
                }
                catch (DtoExcecao ex)
                {
                    retorno = ex.ToDto();
                }
                catch (Exception ex)
                {
                    retorno = new DtoRetornoErro(ex.Message);
                }
            }
            else
            {
                string camposInvalidos = "";
                if (usuario.nome.Length >= 3) camposInvalidos += "Nome\n";
                if (rg.IsMatch(usuario.email)) camposInvalidos += "E-mail\n";
                if (usuario.senha.Length > 3) camposInvalidos += "Senha";
                retorno = (new DtoExcecao(DTO.Enum.CampoInvalido, camposInvalidos)).ToDto();
            }

            return js.Serialize(retorno);
        }
コード例 #16
0
        public string pesquisarProdutos(string dtoChave, string dtoEnderecoEstabelecimento, string parametros)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoEnderecoEstabelecimento enderecoEstabelecimento = js.Deserialize<DtoEnderecoEstabelecimento>(dtoEnderecoEstabelecimento);
            DtoProduto parametrosProduto = js.Deserialize<DtoProduto>(parametros);
            DtoItem[] produtosDoEstabelecimento;

            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Estabelecimento mEstabelecimento = new Estabelecimento();
                chave = mChave.atualizarChave(chave);
                produtosDoEstabelecimento = mEstabelecimento.procurarProduto(enderecoEstabelecimento, parametrosProduto);
                retorno = new DtoRetornoObjeto(chave, produtosDoEstabelecimento);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: Array de DtoItem com DtoProduto*/
            return js.Serialize(retorno);
        }
コード例 #17
0
        public string listarEstabelecimentosProssuidores(string dtoChave, string dtoProduto)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno = new DtoRetorno("ACK");
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoProduto produto = js.Deserialize<DtoProduto>(dtoProduto);

            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Produto mProduto = new Produto();
                DtoItem[] itens = mProduto.estabelecimentosPossuidores(produto.id);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, itens);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: DtoItem com DtoProduto com DtoTipoProduto e DtoFabricante*/
            return js.Serialize(retorno);
        }
コード例 #18
0
        public string finalizarCheckin(string dtoChave, string dtoEnderecoEstabelecimento, string dtoItensComprados)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoEnderecoEstabelecimento enderecoEstabelecimento = js.Deserialize<DtoEnderecoEstabelecimento>(dtoEnderecoEstabelecimento);
            List<DtoProdutoDaLista> itensComprados = js.Deserialize<List<DtoProdutoDaLista>>(dtoItensComprados);

            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Estabelecimento mEstabelecimento = new Estabelecimento();
                enderecoEstabelecimento = mEstabelecimento.abrirEstabelecimento(enderecoEstabelecimento.id);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave);

                Produto mProduto = new Produto();
                Item mItem = new Item();
                foreach (DtoProdutoDaLista produtoDaLista in itensComprados)
                {
                    if (produtoDaLista.item.produto.id == 0)
                        produtoDaLista.item.produto = mProduto.cadastrarProduto(produtoDaLista.item.produto);

                    produtoDaLista.item = mItem.criarItem(produtoDaLista.item.produto.id, produtoDaLista.item.preco, enderecoEstabelecimento.id);
                }
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: DtoRetorno com Ack*/
            return js.Serialize(retorno);
        }
コード例 #19
0
        public string listarItensEm(string dtoChave, string dtoLista, string dtoEnderecoEstabelecimento)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            DtoRetorno retorno;
            DtoChave chave = js.Deserialize<DtoChave>(dtoChave);
            DtoLista lista = js.Deserialize<DtoLista>(dtoLista);
            DtoEnderecoEstabelecimento estabelecimento = js.Deserialize<DtoEnderecoEstabelecimento>(dtoEnderecoEstabelecimento);

            Chave mChave = new Chave();

            try
            {
                mChave.validarChave(chave);
                Lista mLista = new Lista();
                lista = mLista.listarItensEm(lista.id, estabelecimento.id);
                chave = mChave.atualizarChave(chave);
                retorno = new DtoRetornoObjeto(chave, lista);
            }
            catch (DtoExcecao ex)
            {
                retorno = ex.ToDto();
            }
            catch (Exception ex)
            {
                retorno = new DtoRetornoErro(ex.Message);
            }

            /*Objeto: DtoLista com array de DtoProdutoDaLista contendo DtoProduto e DtoItem (no mesmo indice, caso o item exista), contendo o endereço do estab e o estab*/
            return js.Serialize(retorno);
        }