public void UpdateInsurance(int insuranceId, Insurance insurance) { using (var dataContext = new eHealthCareEntities()) { try { var insuranceToUpdate = GetInsuranceById(insurance.PatientId, insuranceId); if (insuranceToUpdate != null) { insuranceToUpdate.PlanName = insurance.PlanName; insuranceToUpdate.CoverageType = insurance.CoverageType; insuranceToUpdate.IsPrimary = insurance.IsPrimary; insuranceToUpdate.GroupNumber = insurance.GroupNumber; insuranceToUpdate.SubscriberID = insurance.SubscriberID; insuranceToUpdate.SubscriberDOB = insurance.SubscriberDOB; insuranceToUpdate.SubscriberDate = insurance.SubscriberDate; insuranceToUpdate.ExpirationDate = insurance.ExpirationDate; dataContext.Insurances.Attach(insuranceToUpdate); dataContext.Entry(insuranceToUpdate).State = EntityState.Modified; dataContext.SaveChanges(); } } catch (DbEntityValidationException ex) { throw new Exception(ex.EntityValidationErrors.GetValidationErrors()); } catch { throw; } } }
public void SaveInsurance(Insurance insurance) { using (var dataContext = new eHealthCareEntities()) { try { dataContext.Insurances.Add(insurance); dataContext.SaveChanges(); } catch (DbEntityValidationException ex) { throw new Exception(ex.EntityValidationErrors.GetValidationErrors()); } catch { throw; } } }