示例#1
0
        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);
            }
        }
示例#2
0
        private async void Salvar_ClickedAsync(object sender, EventArgs e)
        {
            try
            {
                //Recebe informações
                Models.Cadastro novoCadastro = new Models.Cadastro
                {
                    id    = cadastro.id,
                    login = cadastro.login.Trim(),
                    senha = cadastro.senha.Trim(),
                    nome  = txtNome.Text.Trim(),
                    email = cadastro.email.Trim(),
                    cpf   = cadastro.cpf.Trim()
                };

                if (novoCadastro.nome.Equals(""))
                {
                    await DisplayAlert("Erro:", "Nome vazio", "OK");
                }
                else
                {
                    await DisplayAlert("Sucesso:", "Nome alterado com sucesso!", "OK");

                    await ds.UpdateCadastroAsync(novoCadastro);

                    Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 1]);
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Erro:", "Nome vazio", "OK");
            }
        }
示例#3
0
        public async void MudaSenha(Models.Cadastro cadastro, string senha)
        {
            CadastroDataService ds = new CadastroDataService();

            cadastro.senha = senha;
            await ds.UpdateCadastroAsync(cadastro);
        }
示例#4
0
        private async void Salvar_ClickedAsync(object sender, EventArgs e)
        {
            try
            {
                //Recebe informações
                Models.Cadastro novoCadastro = new Models.Cadastro
                {
                    id    = cadastro.id,
                    login = cadastro.login.Trim(),
                    senha = txtNovaSenha.Text.Trim(),
                    nome  = cadastro.nome.Trim(),
                    email = cadastro.email.Trim(),
                    cpf   = cadastro.cpf.Trim()
                };
                string confSenha = txtConfSenha.Text.Trim();

                string result; //Mensagem a ser exibida
                result = controller.AlterarSenha(novoCadastro, cadastro, confSenha);

                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.UpdateCadastroAsync(novoCadastro);

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