public void SeedSurveyDb() { _ctx.Database.EnsureCreated(); if (!_ctx.Questions.Any()) { // Need to create question data var filepath = Path.Combine(_hosting.ContentRootPath, "Data/Seed/questions.json"); var json = File.ReadAllText(filepath); var questions = JsonConvert.DeserializeObject <IEnumerable <SurveyQuestion> >(json); _ctx.Questions.AddRange(questions); _ctx.SaveChanges(); // Need to create choices data filepath = Path.Combine(_hosting.ContentRootPath, "Data/Seed/choices.json"); json = File.ReadAllText(filepath); var choices = JsonConvert.DeserializeObject <IEnumerable <SurveyChoice> >(json); _ctx.Choices.AddRange(choices); _ctx.SaveChanges(); } }
public bool SaveAll() { return(_ctx.SaveChanges() > 0); }