public void ClearAllEntitiesInDatabase() { using (var db = new SmartPoolContext()) { Console.WriteLine("This action wil clear the entire SmartPool user database (yes/no)."); if (SecurityCheck() == true) { //These commands need to be parameterized db.Database.ExecuteSqlCommand("DELETE [MonitorUnits]"); Console.WriteLine("Clearing MonitorUnits..."); db.Database.ExecuteSqlCommand("DELETE [Pools]"); Console.WriteLine("Clearing pools..."); db.Database.ExecuteSqlCommand("DELETE [UserEntities]"); Console.WriteLine("Clearing UserEntities..."); db.Database.ExecuteSqlCommand("DELETE [RealNames]"); Console.WriteLine("Clearing RealNames"); Console.WriteLine("************************************************************"); Console.WriteLine("******************** All tables cleared! *******************"); Console.WriteLine("************************************************************"); db.SaveChanges(); } else { return; } } }
public void AddUserToDatabase(User user) { using (var db = new SmartPoolContext()) { db.Users.Add(user); db.SaveChanges(); } }