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); } }
public async Task UpdateCombustivelAsync(Models.Combustivel combustivel) { string url = "http://www.testeleo.somee.com/api/combustivel/{0}"; var uri = new Uri(string.Format(url, combustivel.id)); var data = JsonConvert.SerializeObject(combustivel); var content = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; response = await client.PutAsync(uri, content); if (!response.IsSuccessStatusCode) { throw new Exception("Erro ao atualizar Combustivel"); } }
public Models.Combustivel GetCombustivelByCadastro(List <Models.Combustivel> combustiveis, string login) { for (int i = 0; i < combustiveis.Count; i++) { if (combustiveis[i].login.Trim().Equals(login)) { return(combustiveis[i]); //Retorna o combustível do usuário } } Models.Combustivel combustivel = new Models.Combustivel { login = login, etanol = 0, diesel = 0, gasolina = 0, outro = 0 }; AddCombustivel(combustivel); //Se não houver combustível cadastrado para o usuário, cadastra um novo combustível return(combustivel); }
public async void AddRelatorio(Models.Relatorio relatorio, Models.Combustivel combustivel, Models.Carro carro, int combustivelUtilizado) { switch (combustivelUtilizado) { case 0: relatorio.custo = float.Parse((relatorio.kmpercorridos * combustivel.etanol / carro.kmlitro).ToString()); break; case 1: relatorio.custo = float.Parse((relatorio.kmpercorridos * combustivel.gasolina / carro.kmlitro).ToString()); break; case 2: relatorio.custo = float.Parse((relatorio.kmpercorridos * combustivel.diesel / carro.kmlitro).ToString()); break; case 3: relatorio.custo = float.Parse((relatorio.kmpercorridos * combustivel.outro / carro.kmlitro).ToString()); break; } RelatorioDataService ds = new RelatorioDataService(); await ds.AddRelatorioAsync(relatorio); }
public async Task DeleteCombustivelAsync(Models.Combustivel combustivel) { string url = "http://www.testeleo.somee.com/api/combustivel/{0}"; var uri = new Uri(string.Format(url, combustivel.id)); await client.DeleteAsync(uri); }
private async void AddCombustivel(Models.Combustivel combustivel) { CombustivelDataService ds = new CombustivelDataService(); await ds.AddCombustivelAsync(combustivel); }