Example #1
0
        public void DeleteEnd()
        {
            //var deleteOrderDetails =
            //    from details in lContext.Persons
            //    where details.Id  == this.Id
            //    select details;


            DataSource.Supplier lDeleted = lContext.Suppliers.SingleOrDefault(p => p.Id == this.Id);

            if (lDeleted != null)
            {
                lContext.Suppliers.DeleteOnSubmit(lDeleted);

                try
                {
                    lContext.SubmitChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    // Provide for exceptions.
                }
            }
        }
Example #2
0
        public void EndEdit()
        {
            DataSource.Supplier lUpdate = lContext.Suppliers.SingleOrDefault(p => p.Id == this.Id);


            if (lUpdate == null)
            {
                DataSource.Supplier newItem = new DataSource.Supplier
                {
                    Id             = this.Id,
                    Contact        = this.ContactId,
                    Name           = this.SupplierName,
                    BillingAddress = this.BillingAddress,
                };
                // Add the new object to the Orders collection.
                lContext.Suppliers.InsertOnSubmit(newItem);

                // Submit the change to the database.
                try
                {
                    lContext.SubmitChanges();

                    this.Id = newItem.Id;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            else
            {
                lUpdate.Contact        = this.ContactId;
                lUpdate.Name           = this.SupplierName;
                lUpdate.BillingAddress = this.BillingAddress;

                lContext.SubmitChanges();
            }
        }