// D e l e t e public bool DeleteDailyRoutine(int id) { DailyRoutine dailyRoutineToDelete = context.DailyRoutines.FirstOrDefault(dr => dr.Id == id); if (dailyRoutineToDelete == null) { return(false); } context.DailyRoutines.Remove(dailyRoutineToDelete); context.SaveChanges(); return(true); }
// M e t h o d s - C R U D // C r e a t e public DailyRoutine Create(DailyRoutine dailyRoutine) { try { context.DailyRoutines.Add(dailyRoutine); context.SaveChanges(); return(dailyRoutine); } catch (Exception e) {//something bad happened! return(null); } }
// U p d a t e public DailyRoutine UpdateDailyRoutine(DailyRoutine dailyRoutine) { //1. Go find (read) this product from the database DailyRoutine dailyRoutineToUpdate = context.DailyRoutines //This will return an IQueryable .FirstOrDefault(dr => dr.Id == dailyRoutine.Id); //gets one product out of the database //2. Modify the database copy of the product if (dailyRoutineToUpdate != null) { dailyRoutineToUpdate.Date = dailyRoutine.Date; dailyRoutineToUpdate.Food = dailyRoutine.Food; dailyRoutineToUpdate.Poop = dailyRoutine.Poop; dailyRoutineToUpdate.Pee = dailyRoutine.Pee; dailyRoutineToUpdate.Id = dailyRoutine.Id; //3. Dear Database: Please update you copy of this product context.SaveChanges(); } return(dailyRoutineToUpdate); }