public void UpdateDietaryIntake(int dietaryIntakeId, DietaryIntake dietaryIntake) { using (var dataContext = new eHealthCareEntities()) { try { var dietaryIntakeToUpdate = GetDietaryIntakesById(dietaryIntake.PatientId, dietaryIntakeId); if (dietaryIntakeToUpdate != null) { dietaryIntakeToUpdate.Calories = dietaryIntake.Calories; dietaryIntakeToUpdate.Date = dietaryIntake.Date; dietaryIntakeToUpdate.Meal = dietaryIntake.Meal; dietaryIntakeToUpdate.Name = dietaryIntake.Name; dietaryIntakeToUpdate.Notes = dietaryIntake.Notes; dataContext.DietaryIntakes.Attach(dietaryIntakeToUpdate); dataContext.Entry(dietaryIntakeToUpdate).State = EntityState.Modified; dataContext.SaveChanges(); } } catch (DbEntityValidationException ex) { throw new Exception(ex.EntityValidationErrors.GetValidationErrors()); } catch { throw; } } }
public void SaveDietaryIntake(DietaryIntake dietaryIntake) { using (var dataContext = new eHealthCareEntities()) { try { dataContext.DietaryIntakes.Add(dietaryIntake); dataContext.SaveChanges(); } catch (DbEntityValidationException ex) { throw new Exception(ex.EntityValidationErrors.GetValidationErrors()); } catch { throw; } } }