public static void Initialize(IServiceProvider serviceProvider) { using (var context = new TermContext(serviceProvider.GetRequiredService <DbContextOptions <TermContext> >())) { if (context.Term.Any()) { return; } context.Term.AddRange( new Term { Terms = "Force", Subject = "Physics", Definitions = "A Force is any interaction that, when unopposed, will change the motion of an object.", Questions = "What is a Force?", Answers = "A Force is any interaction that, when unopposed, will change the motion of an object." }, new Term { Terms = "Differential Equation", Subject = "Math", Definitions = "an equation that relates one or more functions and their derivatives", Questions = "What is a Differential Equation?", Answers = "A differential equation is an equation that relates one or more functions and their derivatives" }); context.SaveChanges(); } }
public async Task <IActionResult> AddTerm(string term) { if (!string.IsNullOrEmpty(term)) { try { _db.Terms.Add(new Term { Text = term }); _db.SaveChanges(); return(Json(new { success = true, term = new { Text = term } })); } catch (Exception) { return(Json(new { succeess = false })); } } else { return(Json(new { success = false })); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new TermContext(serviceProvider.GetRequiredService <DbContextOptions <TermContext> >())) { // Look for any movies. if (context.Term.Any()) { return; // DB has been seeded } context.Term.AddRange( new Term { TermID = 1, Terms = "Physics", Subject = "General Information", Definitions = "Physics is the branch of science concerned with the nature and properties of matter and energy", Questions = "What is Physics?", Answers = "Physics is the branch of science concerned with the nature and properties of matter and energy" } ); context.SaveChanges(); } }