//mudando de bool para refeicao public Refeicao createRefeicao(Refeicao refeicao) { using (NutricaoContext mde = new NutricaoContext()) { try { Debug.Write("Entrou no create"); refeicao.dataDeCriacao = DateTime.Today; mde.Refeicao.Add(refeicao); mde.SaveChanges(); return refeicao; } catch (Exception ex) { Debug.Write(ex.ToString()); return null; } }; }
public bool editRefeicao(Refeicao refeicao) { using (NutricaoContext mde = new NutricaoContext()) { var result = mde.Refeicao.SingleOrDefault(r => r.Id == refeicao.Id); if (result != null) { //mde.Refeicao.Add(refeicao); mde.Entry(refeicao).State = EntityState.Modified; mde.SaveChanges(); return true; } else { return false; } }; }
public bool deleteRefeicao(Refeicao refeicao) { using (NutricaoContext mde = new NutricaoContext()) { var result = mde.Refeicao.Where(rf => rf.Id == refeicao.Id).SingleOrDefault(); if (result != null) { mde.Refeicao.Remove(result); mde.SaveChanges(); return true; } else { return false; } }; }