public static bool SalvarXML(string NomeArquivo, Refeicao refeicao) { try { XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; using (IsolatedStorageFile myISF = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream stream = myISF.OpenFile(NomeArquivo, FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(List<Alimento>)); using (XmlWriter xmlWriter = XmlWriter.Create(stream)) { serializer.Serialize(xmlWriter, refeicao.Alimentos); } } } } catch (System.IO.IOException) { return false; } return true; }
public static List<Alimento> LerRefeicaoXML(string NomeArquivo, Refeicao refeicao) { try { List<Alimento> listaAlimentos; using (IsolatedStorageFile myISF = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream stream = myISF.OpenFile(NomeArquivo, FileMode.Open)) { XmlSerializer serializer = new XmlSerializer(typeof(List<Alimento>)); stream.Position = 0; listaAlimentos = (List<Alimento>)serializer.Deserialize(stream); refeicao.Alimentos = listaAlimentos; } } return listaAlimentos; } catch (Exception) { return null; } }
public bool Gravar(Refeicao novaRefeicao) { try { using (DataBaseContext db = new DataBaseContext(DataBaseContext.ConnectionString)) { //db.Tarefas.InsertOnSubmit(novaTarefa); db.SubmitChanges(); } return true; } catch (Exception) { return false; } }
public bool Excluir(Refeicao refeicao) { try { using (DataBaseContext db = new DataBaseContext(DataBaseContext.ConnectionString)) { var excluir = db.Refeicoes.Where(refe => refe.IdRefeicao == refe.IdRefeicao).First(); db.Refeicoes.DeleteOnSubmit(excluir); db.SubmitChanges(); } return true; } catch (Exception) { return false; } }
public bool Realizado(Refeicao refeicao) { try { using (DataBaseContext db = new DataBaseContext(DataBaseContext.ConnectionString)) { Refeicao update = (from refe in db.Refeicoes where refe.IdRefeicao == refeicao.IdRefeicao select refe).First(); update.Realizada = !update.Realizada; db.SubmitChanges(); } return true; } catch (Exception) { return false; } }