Exemple #1
0
 /// <summary>
 /// Loads the object with the given id. Throws an exception if not found
 /// </summary>
 /// <param name="itemId">the id of the item to load</param>
 /// <returns>The object with the given id</returns>
 public static Item Load(int itemId)
 {
     Item bo = new Item();
     DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
     DAL.Item dalItem = findRecord(dc, itemId);
     map(dalItem, ItemPricing.LoadWithItemId(dc, itemId), bo);
     return bo;
 }
        internal static PaymentType Load(int paymentTypeId)
        {
            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.PaymentType dalPaymentType = findRecord(dc, paymentTypeId);

            PaymentType bo = new PaymentType();
            map(dalPaymentType, bo);
            return bo;
        }
        // Load will return null if the dalItem is not found, or throw an exception if an error happens
        public static Payment Load(int paymentId)
        {
            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.PaymentHeader ph = findRecord(dc, paymentId);

            Payment bo = new Payment();
            map(ph, PaymentTransaction.LoadWithPaymentId(dc, paymentId), bo);

            return bo;
        }
        public static Invoice Load(int invoiceId)
        {
            Invoice bo = null;
            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.InvoiceHeader ih = findRecord(dc, invoiceId);

            if (ih != null)
            {
                bo = new Invoice((Type)Enum.Parse(typeof(Type), ih.InvoiceType));
                map(ih, InvoiceDetail.LoadWithInvoiceId(dc, invoiceId), bo);
            }

            return bo;
        }
        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);
            }
        }
        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);
            }
        }
        /// <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);
            }
        }
 internal void ModifyBalance(decimal amount)
 {
     using (var dc = new DAL.CustomersDataContext())
     {
         dc.Customers.Single(c => c.Id == this.Id).Balance += amount;
         dc.SubmitChanges();
     }
 }
        internal static Customer LoadWithUserId(int userId)
        {
            DAL.CustomersDataContext dc = new DAL.CustomersDataContext();
            DAL.Customer c = findRecordByUserId(dc, userId);

            Customer bo = new Customer();
            map(c,
                dc.CustomerTypes.Where(ct => ct.Id == c.CustomerTypeId).Single(),
                Address.LoadWithCustomerId(dc, c.Id),
                Phone.LoadWithCustomerId(dc, c.Id),
                Login.LoadWithCustomerId(dc, c.Id),
                bo);

            return bo;
        }
        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);
            }
        }
Exemple #11
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);
            }
        }
Exemple #12
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);
            }
        }
Exemple #13
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);
            }
        }
Exemple #14
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);
            }
        }