public void UpdateWeight(int weightId, Weight weight) { using (var dataContext = new eHealthCareEntities()) { try { var weightToUpdate = GetWeightById(weight.PatientId, weightId); if (weightToUpdate != null) { weightToUpdate.Date = weight.Date; weightToUpdate.Weight1 = weight.Weight1; weightToUpdate.WeightGoal = weight.WeightGoal; dataContext.Weights.Attach(weightToUpdate); dataContext.Entry(weightToUpdate).State = EntityState.Modified; dataContext.SaveChanges(); } } catch (DbEntityValidationException ex) { throw new Exception(ex.EntityValidationErrors.GetValidationErrors()); } catch { throw; } } }
public void SaveWeight(Weight weight) { using (var dataContext = new eHealthCareEntities()) { try { dataContext.Weights.Add(weight); dataContext.SaveChanges(); } catch (DbEntityValidationException ex) { throw new Exception(ex.EntityValidationErrors.GetValidationErrors()); } catch { throw; } } }