public IEnumerable<Location> GetLocationList() { TestDBContext _db = new TestDBContext(); var query = from loc in _db.Locations select loc; return query.ToList(); }
public static IEnumerable<Customer> GetCustomers() { TestDBContext _db = new TestDBContext(); var query = from cust in _db.Customers select cust; return query.ToList(); }
// DELETE api/locationapi/5 public void Delete(int id) { TestDBContext _db = new TestDBContext(); try { Location loc = _db.Locations.Where((c) => c.ID == id).FirstOrDefault(); Debug.WriteLine("deleting loc: " + loc.ID); _db.Locations.Remove(loc); _db.SaveChanges(); } catch { Debug.WriteLine("failed on delete"); } }
//public static void DeleteCustomer(Customer cust) //{ // TestDBContext _db = new TestDBContext(); // try // { // _db.Customers.Remove(cust); // _db.SaveChanges(); // } // catch // { // Debug.WriteLine("failed on delete"); // } //} public static void DeleteCustomer(int id) { TestDBContext _db = new TestDBContext(); try { Customer cust = _db.Customers.Where((c) => c.ID == id).FirstOrDefault(); Debug.WriteLine("deleting cust: " + cust.ID + "; Name: " + cust.Name); _db.Customers.Remove(cust); _db.SaveChanges(); } catch { Debug.WriteLine("failed on delete"); } }
public static void InsertLocation(Location loc) { TestDBContext _db = new TestDBContext(); _db.Locations.Add(loc); _db.SaveChanges(); }
public static void InsertCustomer(Customer cust) { TestDBContext _db = new TestDBContext(); _db.Customers.Add(cust); _db.SaveChanges(); }