コード例 #1
0
 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;
     }
 }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
    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);
    }
コード例 #4
0
        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;
                }
            }
        }