public void InsertOrUpdate(Customer customer) { if (customer.ID == default(int)) { CustomerCache.Add(customer); //this.context.Customers.Add(customer); } else { this.context.Entry(customer).State = EntityState.Modified; } }
private void EnsureCacheInitialized() { System.Diagnostics.Trace.WriteLine("Listing Customers"); if (CustomerCache == null) { CustomerCache = new List <Customer>(); } foreach (var c in this.context.Customers) { CustomerCache.Add(c); } }
public static T GetData <T>(string key, Func <T> func) { T result = default(T); if (CustomerCache.Contains(key)) { result = CustomerCache.Get <T>(key); } else { result = func.Invoke(); CustomerCache.Add(key, result); } return(result); }
private void mnuEditAdd_Click(object sender, EventArgs e) { Customer customer = new Customer() { CustomerId = Guid.NewGuid() }; using (CustomerForm f = new CustomerForm( customer, EntityOperation.Add, new PropertyValueExists(_customerCache.PropertyValueExists))) { if (f.ShowDialog() == DialogResult.OK) { _customerCache.Add(customer); Refresh(false); _unsavedChanges = true; } } }