/* * LÍQUIDO: 1 * Vegetal: 2 * Grãos: 3 * Frutas: 4 * Proteínas: 5 * PÃO: 6 */ //TRATAMENDO DINÂMICO: /// <summary> /// Grava no banco um alimento. /// </summary> /// <param name="alimento">Instância de alimento.</param> /// <returns> [true]: se cadastrou; [false]: se não cadastrou;</returns> public static bool Gravar(AlimentoView alimento) { try { App thisApp = Application.Current as App; thisApp.LINDADB.AlimentoItems.InsertOnSubmit(alimento); thisApp.LINDADB.SubmitChanges(); } catch (Exception error) { MessageBox.Show(error.Message, "Erro", MessageBoxButton.OK); return(false); } return(true); }
/// <summary> /// Exclui um alimento. /// </summary> /// <param name="alimento">Instância de alimento.</param> /// <returns> [true]: se conseguiu; [false]: se não conseguiu;</returns> public static bool Excluir(AlimentoView alimento) { try { App thisApp = Application.Current as App; var excluir = thisApp.LINDADB.AlimentoItems.Where(a => a.Id_alimento == alimento.Id_alimento).First(); thisApp.LINDADB.AlimentoItems.DeleteOnSubmit(excluir); thisApp.LINDADB.SubmitChanges(); } catch (Exception error) { MessageBox.Show(error.Message, "Erro", MessageBoxButton.OK); return(false); } return(true); }
/// <summary> /// Altera um alimento. /// </summary> /// <param name="alimento">Instância de alimento.</param> /// <param name="novoQTD">Nova quantidade.</param> /// <returns> [true]: se cadastrou; [false]: se não cadastrou;</returns> public static bool Alterar(AlimentoView alimento, int novoQTD) { try { App thisApp = Application.Current as App; AlimentoView update = (from com in thisApp.LINDADB.AlimentoItems where com.Id_alimento == alimento.Id_alimento select com).First(); update.Quantidade = novoQTD; thisApp.LINDADB.SubmitChanges(); } catch (Exception) { return(false); } return(true); }
public static ImageSource ImgConvertedSource(AlimentoView pAlimento) { return(new BitmapImage(new Uri(pAlimento.Img_source, UriKind.RelativeOrAbsolute))); }