public void createLocation(location location) { using (var db = new DataContext()) { bool dbexist = db.Database.Exists(); if (dbexist == true) { db.location.Add(location); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } } }
public void NewAction(object commandParam) { location newlocation = new location(); Locations.Add(newlocation); SelectedItem = newlocation; }
public void updateLocation(location location) { if (location.location_id != 0) { using (var db = new DataContext()) { bool dbexist = db.Database.Exists(); if (dbexist == true) { var query = from qlocation in db.location where qlocation.location_id == location.location_id select qlocation; foreach (location elocation in query) { elocation.name = location.name; elocation.description = location.description; } try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } } } else { createLocation(location); } }