public void Update(Models.Survey.SurveyModel survey) { try { db.Entry(survey).State = EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { Log.Error(ex.Message, ex); } }
public long Save(Models.Survey.SurveyModel survey) { try { db.SurveyModels.Add(survey); db.SaveChanges(); return(survey.SurveyID); } catch (Exception ex) { Log.Error(ex.Message, ex); return(-1); } }
public void Delete(Models.Survey.SurveyModel survey) { try { db.Database.ExecuteSqlCommand("DELETE FROM SurveyParameters WHERE SurveyModel_SurveyID = {0}", new object[] { survey.SurveyID }); foreach (var surveyInstance in survey.SurveyInstances) { db.Database.ExecuteSqlCommand("DELETE FROM SurveyKeyValues WHERE SurveyInstance_SurveyInstanceID = {0}", new object[] { surveyInstance.SurveyInstanceID }); } db.SurveyModels.Remove(survey); db.SaveChanges(); db.Database.ExecuteSqlCommand("DELETE FROM SurveyInstances WHERE SurveyModel_SurveyID IS NULL"); } catch (Exception ex) { Log.Error(ex.Message, ex); } }