Exemplo n.º 1
0
        private static async Task <Cliente> getClientByString(List <String> x)
        {
            Cliente cliente = new Cliente();

            //verifica se a primeira linha é um modelo de aparelho, se sim cliente não existe
            if (x[0] == Regex.Match(x[0], @"[A-Z]*-(?:\d+[A-Z]|[A-Z]+\d)[A-Z\d]*").Value)
            {
                return(null);
            }

            //verifica se a primeira linha é cpf
            if (Regex.Match(x[0], @"[0-9]{11}").Value == x[0])
            {
                cliente.Cpf = x[0];
                return(cliente);
            }


            if ((cliente.Contatar = x[0].Contains("/1") ? 2 : 1) == 1)
            {
                x[0] = x[0].Replace("/1", " ");
            }

            if (Regex.Split(x[0], " ").Count() == 1)
            {
                return(null);
            }

            cliente.Nome      = Regex.Split(x[0], " ")[0];
            cliente.Sobrenome = x[0].Replace(Regex.Split(x[0], " ")[0] + " ", "");
            cliente.Cpf       = x[1];
            cliente.Telefone  = x[2].Length == 10 ? x[2] : "";
            cliente.Celular   = x[2].Length == 11 ? x[2] : "";
            cliente.Sexo      = await IBGEApi.GetSexoIBGE(Regex.Split(x[0], " ")[0]);

            //cliente.Sexo = x[3] == "M" ? "Masculino"  : "Feminino";
            return(cliente);
        }
Exemplo n.º 2
0
        public async Task <Cliente> RegisterNewCliente(Cliente cliente)
        {
            if (cliente.Sexo == null)
            {
                cliente.Sexo = await IBGEApi.GetSexoIBGE(cliente.Nome);
            }
            try
            {
                dynamic httpContent = await WebRequestHelper.PostRequestAsync(
                    "http://biz6.samsungcsportal.com/gspn/operate.do",
                    "cmd=SVCPopCustomerCreateCmd&numPerPage=10&currPage=0&BP_TYPE=C001&TITLE=000" + (cliente.Sexo == "F" ? "1" : "2") +
                    "&NAME_FIRST=" + cliente.Nome +
                    "&NAME_LAST=" + cliente.Sobrenome +
                    "&GENDER=" + cliente.Sexo +
                    "&UNIQUE_ID=" + cliente.Cpf +
                    "&PREFERENCE_CHANNEL=" + cliente.Sexo +
                    "&HOME_PHONE=" + cliente.Telefone +
                    "&OFFICE_PHONE=&OFFICE_PHONE_EXT=" +
                    "&MOBILE_PHONE=" + cliente.Celular +
                    "&FAX=&EMAIL=&CONTACT_FLAG=" + cliente.Contatar +
                    "&STREET1=&STREET2=&STREET3=&DISTRICT=&CITY=&CITY_CODE=&REGION=Acre&REGION_CODE=AC&COUNTRY=BR&POST_CODE=");

                Cliente c = await GetClienteByCPF(cliente.Cpf, cliente);

                if (c == null)
                {
                    return(null);
                }
                return(c);
            }
            catch (Exception e)
            {
                Console.WriteLine("Erro ao cliar cliente : " + e.Message);
                return(null);
            }
        }