Esempio n. 1
0
        public void Save()
        {
            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.PaymentHeader dalPaymentHeader = null;

            if (this.Id == 0)
            {
                dalPaymentHeader = new DAL.PaymentHeader();
                map(dc, this, dalPaymentHeader);
                dc.PaymentHeaders.InsertOnSubmit(dalPaymentHeader);
            }
            else
            {
                dalPaymentHeader = findRecord(dc, this.Id);
                map(dc, this, dalPaymentHeader);
            }

            dc.SubmitChanges();
            this.Id = dalPaymentHeader.Id;

            foreach (var item in this.PaymentTransactions)
            {
                item.SaveDependent(dc, dalPaymentHeader);
            }
            foreach (var item in PaymentTransaction.LoadWithPaymentId(dc, dalPaymentHeader.Id))
            {
                if (!this.PaymentTransactions.Contains(item))
                    PaymentTransaction.Delete(dc, item);
            }
        }
Esempio n. 2
0
        public void Delete()
        {
            if (this.Id == 0)
                throw new InvalidOperationException("Object has not been persisted, and thus cannot be deleted");

            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.PaymentHeader dalPaymentHeader = findRecord(dc, this.Id);
            dalPaymentHeader.Deleted = true;
            dc.SubmitChanges();

            // delete all dependent objects
            foreach (var item in this.PaymentTransactions)
            {
                PaymentTransaction.Delete(dc, item);
            }
        }
Esempio n. 3
0
 internal void ModifyBalance(decimal amount)
 {
     using (var dc = new DAL.CustomersDataContext())
     {
         dc.Customers.Single(c => c.Id == this.Id).Balance += amount;
         dc.SubmitChanges();
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Saves the object to the db. Throws an exception if any the required values has not been set
        /// </summary>
        internal void Save(int actionPerformerId)
        {
            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.Customer dalCustomer = null;

            if (this.Id == 0)
            {
                dalCustomer = new DAL.Customer();
                map(dc, this, dalCustomer, actionPerformerId);
                dc.Customers.InsertOnSubmit(dalCustomer);
            }
            else
            {
                dalCustomer = findRecord(dc, this.Id);
                map(dc, this, dalCustomer, actionPerformerId);
            }

            dc.SubmitChanges();
            this.Id = dalCustomer.Id;

            // save all new objects and update existing ones if modified
            foreach (var item in this.Addresses)
            {
                item.SaveDependent(dc, dalCustomer, actionPerformerId);
            }
            // delete all missing objects
            foreach (var item in Address.LoadWithCustomerId(dc, this.Id))
            {
                if (!this.Addresses.Contains(item))
                    Address.Delete(dc, item);
            }

            foreach (var item in this.Phones)
            {
                item.SaveDependent(dc, dalCustomer);
            }
            foreach (var item in Phone.LoadWithCustomerId(dc, this.Id))
            {
                if (!this.Phones.Contains(item))
                    Phone.Delete(dc, item);
            }

            foreach (var item in this.Logins)
            {
                item.SaveDependent(dc, dalCustomer);
            }
            foreach (var item in Login.LoadWithCustomerId(dc, this.Id))
            {
                if (!this.Logins.Contains(item))
                    Login.Delete(dc, item);
            }
        }
Esempio n. 5
0
        public void Delete()
        {
            if (this.Id == 0)
                throw new InvalidOperationException("Object has not been persisted, and thus cannot be deleted");

            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.Customer dalCustomer = findRecord(dc, this.Id);
            dalCustomer.Deleted = true;
            dc.SubmitChanges();

            // delete all dependent objects
            foreach (var item in this.Addresses)
            {
                Address.Delete(dc, item);
            }

            foreach (var item in this.Phones)
            {
                Phone.Delete(dc, item);
            }

            foreach (var item in this.Logins)
            {
                Login.Delete(dc, item);
            }
        }
Esempio n. 6
0
        public void Delete()
        {
            if (this.Id == 0)
                throw new InvalidOperationException("Object has not been persisted, and thus cannot be deleted");

            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.Item dalItem = findRecord(dc, this.Id);
            dalItem.Deleted = true;
            dc.SubmitChanges();

            foreach (var item in this.ItemPricings)
            {
                ItemPricing.Delete(dc, item);
            }
        }
Esempio n. 7
0
        public void Save()
        {
            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.Item dalItem = null;

            if (this.Id == 0)
            {
                dalItem = new CustomerManagement.DAL.Item();
                map(this, dalItem);
                dc.Items.InsertOnSubmit(dalItem);
            }
            else
            {
                dalItem = findRecord(dc, this.Id);
                map(this, dalItem);
            }

            dc.SubmitChanges();
            this.Id = dalItem.Id;

            // save all new objects and update existing ones if modified
            foreach (var item in this.ItemPricings)
            {
                item.SaveDependent(dc, dalItem);
            }
            // delete all missing objects
            foreach (var item in ItemPricing.LoadWithItemId(dc, this.Id))
            {
                if (!this.ItemPricings.Contains(item))
                    ItemPricing.Delete(dc, item);
            }
        }
Esempio n. 8
0
        public void Delete()
        {
            if (this.Id == 0)
                throw new InvalidOperationException("Object has not been persisted, and thus cannot be deleted");

            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.InvoiceHeader dalInvoiceHeader = findRecord(dc, this.Id);
            dalInvoiceHeader.Deleted = true;
            dc.SubmitChanges();

            // delete all missing objects
            foreach (var item in this.InvoiceDetails)
            {
                InvoiceDetail.Delete(dc, item);
            }
        }
Esempio n. 9
0
        public void Save()
        {
            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.InvoiceHeader dalInvoiceHeader = null;

            if (this.Id == 0)
            {
                dalInvoiceHeader = new DAL.InvoiceHeader();
                map(this, dalInvoiceHeader);
                dc.InvoiceHeaders.InsertOnSubmit(dalInvoiceHeader);
            }
            else
            {
                dalInvoiceHeader = findRecord(dc, this.Id);
                map(this, dalInvoiceHeader);
            }

            dc.SubmitChanges();
            this.Id = dalInvoiceHeader.Id;

            // save all new objects and update existing ones if modified
            foreach (var item in this.InvoiceDetails)
            {
                item.SaveDependent(dc, dalInvoiceHeader);
            }
            // delete all missing objects
            foreach (var item in InvoiceDetail.LoadWithInvoiceId(dc, this.Id))
            {
                if (!this.InvoiceDetails.Contains(item))
                    InvoiceDetail.Delete(dc, item);
            }
        }