Exemple #1
0
        protected void UpdateCustomerProductsTabel(RadComboBox cmbCustomerProduct, string productId)
        {
            using (DataClasses1DataContext dbContext = new DataClasses1DataContext(((Guid)Session["CurrentUserId"])))
            {
                foreach (RadComboBoxItem Item in cmbCustomerProduct.Items)
                {
                    if (!String.IsNullOrEmpty(Item.Value))
                    {
                        var CustProdRelation = dbContext.CustomerProduct.SingleOrDefault(q => q.CustomerId == new Guid(Item.Value) && q.ProductId == new Guid(productId));

                        if (CustProdRelation != null) // exists
                        {
                            if (Item.Checked) //checked and exists - nothing
                            {

                            }
                            else // exits, but not checked - delete
                            {
                                dbContext.CustomerProduct.DeleteOnSubmit(CustProdRelation);
                            }
                        }
                        else //not exists
                        {
                            if (Item.Checked) //checked and not exists - insert
                            {
                                CustomerProduct newCustProd = new CustomerProduct { CustomerId = new Guid(Item.Value), ProductId = new Guid(productId) };
                                dbContext.CustomerProduct.InsertOnSubmit(newCustProd);
                            }
                            else // not exists and not checked - nothing
                            {
                              //  dbContext.CustomerProduct.DeleteOnSubmit(CustProdRelation);
                            }
                        }

                        dbContext.SubmitChanges();
                    }
                }
            }
        }
		private void detach_CustomerProduct(CustomerProduct entity)
		{
			this.SendPropertyChanging();
			entity.Customer = null;
		}
		private void attach_CustomerProduct(CustomerProduct entity)
		{
			this.SendPropertyChanging();
			entity.Customer = this;
		}
 partial void DeleteCustomerProduct(CustomerProduct instance);
 partial void UpdateCustomerProduct(CustomerProduct instance);
 partial void InsertCustomerProduct(CustomerProduct instance);