private async void UpdateLogin(Models.Cadastro novoCadastro, Models.Cadastro cadastro, List <Models.Cadastro> cadastros)
        {
            CadastroDataService ds = new CadastroDataService();

            if (!novoCadastro.login.Equals(cadastro.login.Trim())) //Se o login foi alterado
            {
                novoCadastro.cpf = cadastro.cpf;
                cadastro.cpf     = "";
                await ds.UpdateCadastroAsync(cadastro);

                await ds.AddCadastroAsync(novoCadastro); //Adciona o cadastro com o login alterado

                CarroDataService       carrods = new CarroDataService();
                CombustivelDataService combds  = new CombustivelDataService();
                LembreteDataService    lemds   = new LembreteDataService();
                List <Models.Carro>    carros  = await carrods.GetCarroAsync();

                List <Models.Combustivel> combustiveis = await combds.GetCombustivelAsync();

                List <Models.Lembrete> lembretes = await lemds.GetLembreteAsync();

                for (int i = 0; i < carros.Count; i++)
                {
                    if (carros[i].dono.Trim().Equals(cadastro.login.Trim())) //Para todo carro com o login alterado, muda para o novo login
                    {
                        Models.Carro carro = new Models.Carro
                        {
                            id              = carros[i].id,
                            placa           = carros[i].placa.Trim(),
                            dono            = novoCadastro.login,
                            modelo          = carros[i].modelo.Trim(),
                            tipocombustivel = carros[i].tipocombustivel.Trim(),
                            kmatual         = carros[i].kmatual,
                            kmlitro         = carros[i].kmlitro,
                            status          = carros[i].status.Trim()
                        };
                        await carrods.UpdateCarroAsync(carro);
                    }
                }
                for (int i = 0; i < combustiveis.Count; i++)
                {
                    if (combustiveis[i].login.Trim().Equals(cadastro.login.Trim())) //Para cada combustivel com o login, muda para o login alterado
                    {
                        Models.Combustivel combustivel = combustiveis[i];
                        combustivel.login = novoCadastro.login;
                        await combds.UpdateCombustivelAsync(combustivel);
                    }
                }
                for (int i = 0; i < lembretes.Count; i++)
                {
                    if (lembretes[i].login.Trim().Equals(cadastro.login.Trim())) //Para cada lembrete com o login, muda para o login alterado
                    {
                        Models.Lembrete lembrete = lembretes[i];
                        lembrete.login = novoCadastro.login;
                        await lemds.UpdateLembreteAsync(lembrete);
                    }
                }
                await ds.DeleteCadastroAsync(cadastro);
            }
        }
Exemple #2
0
        private async void BtnFinalizarCadastro_ClickedAsync(object sender, EventArgs e)
        {
            try
            {
                List <Models.Cadastro> cadastros = await ds.GetCadastroAsync(); //Lista com todos os cadastros

                try
                {
                    string result; //Mensagem a ser exibida

                    //Recebe informações
                    Models.Cadastro cadastro = new Models.Cadastro
                    {
                        login = txtCadLogin.Text.Trim(),
                        senha = txtCadSenha.Text.Trim(),
                        nome  = txtCadNome.Text.Trim(),
                        email = txtCadEmail.Text.Trim(),
                        cpf   = txtCadCpf.Text.Trim()
                    };
                    string confsenha = txtConfSenha.Text.Trim();

                    result = controller.Cadastro(cadastro, confsenha, cadastros);

                    var msg = System.Text.RegularExpressions.Regex.Split(result, ";"); //Faz a separação da mensagem em 3 strings
                    await DisplayAlert(msg[0], msg[1], msg[2]);

                    if (msg[0].Equals("Sucesso"))
                    {
                        await ds.AddCadastroAsync(cadastro);

                        //Adiciona os lembretes padrão ao criar um novo perfil
                        LembreteController lc = new LembreteController();
                        lc.CriarLembretes(cadastro);

                        Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 1]);
                    }
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Erro:", "Preencha todos os campos", "OK");
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Erro:", "Sem conexão com a internet", "OK");
            }
        }