protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
public void migrateUsersToJson() { UsersManagerContext db = new UsersManagerContext(); using (StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath("~/App_Data/Users.json"))) { List <User> users = new List <User>(); foreach (User user in db.Users) { User u = new User(); u.Copy(user); users.Add(u); } sw.WriteLine(JsonConvert.SerializeObject(users)); } db.Dispose(); }
public void migrateCoutriesDataToDataBase() { UsersManagerContext db = new UsersManagerContext(); Country country = db.Countries.FirstOrDefault(); string path = HttpContext.Current.Server.MapPath("~/App_Data/Countries.txt"); if (country == null) { StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath("~/App_Data/Countries.txt")); while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] tokens = line.Split(';'); Country newCountry = new Country(); newCountry.Name = tokens[0]; db.Countries.Add(newCountry); db.SaveChanges(); } sr.Dispose(); } db.Dispose(); }