Example #1
0
 internal void Delete(int id = 0)
 {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Address a = db.Addresses.Where(x => x.ID == id).Where(x => x.active == true).First<Address>();
     a.active = false;
     db.SubmitChanges();
 }
 internal void MatchOrSave()
 {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     try {
         InvoiceAddress address = (from a in db.InvoiceAddresses
                                    where a.first.ToLower().Trim().Equals(this.first.ToLower().Trim()) &&
                                    a.last.ToLower().Trim().Equals(this.last.ToLower().Trim()) &&
                                    a.street1.ToLower().Trim().Equals(this.street1.ToLower().Trim()) &&
                                    a.street2.ToLower().Trim().Equals(this.street2.ToLower().Trim()) &&
                                    a.city.ToLower().Trim().Equals(this.city.ToLower().Trim()) &&
                                    a.state.Equals(this.state) &&
                                    a.postal_code.ToLower().Trim().Equals(this.postal_code.ToLower().Trim())
                                    select a).First();
         this.ID = address.ID;
     } catch {
         try {
             this.country = (from c in db.Countries
                             join st in db.States on c.ID equals st.countryID
                             where st.abbr.Equals(this.state.ToUpper().Trim())
                             select c.name).First();
         } catch { }
         db.InvoiceAddresses.InsertOnSubmit(this);
         db.SubmitChanges();
     }
 }
Example #3
0
 public void Remove(HttpContext ctx, int partID = 0) {
     if (this.payment_id == 0) {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         CartItem i = db.CartItems.Where(x => x.order_id == this.ID).Where(x => x.partID == partID).First<CartItem>();
         db.CartItems.DeleteOnSubmit(i);
         db.SubmitChanges();
         clearShippingType();
     } else {
         UDF.ExpireCart(ctx, this.cust_id);
     }
 }
Example #4
0
 internal void Update(string first, string last, string street1, string street2, string city, int state_id, string zip, bool residential = false) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     this.first = first;
     this.last = last;
     this.street1 = street1;
     this.street2 = street2;
     this.city = city;
     this.state = state_id;
     this.postal_code = zip;
     this.residential = residential;
     db.SubmitChanges();
 }
Example #5
0
        public void Save(List<InvoiceItem> items, List<InvoiceCode> codes) {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            this.created = DateTime.UtcNow;
            this.paid = false;
            try {
                Invoice i = db.Invoices.Where(x => x.curtOrder.Equals(this.curtOrder)).First<Invoice>();
            } catch {
                db.Invoices.InsertOnSubmit(this);
                db.SubmitChanges();

                foreach (InvoiceItem itm in items) {
                    itm.invoiceID = this.id;
                }
                db.InvoiceItems.InsertAllOnSubmit(items);

                foreach (InvoiceCode code in codes) {
                    code.invoiceID = this.id;
                }
                db.InvoiceCodes.InsertAllOnSubmit(codes);
                db.SubmitChanges();
            }

        }
Example #6
0
 public void Update(HttpContext ctx, int partID = 0, int quantity = 0) {
     if (this.payment_id == 0) {
         if (quantity > 0) {
             EcommercePlatformDataContext db = new EcommercePlatformDataContext();
             CartItem i = db.CartItems.Where(x => x.order_id == this.ID).Where(x => x.partID == partID).First<CartItem>();
             i.quantity = quantity;
             db.SubmitChanges();
         } else {
             Remove(ctx, partID);
         }
         clearShippingType();
     } else {
         UDF.ExpireCart(ctx,this.cust_id);
     }
 }
Example #7
0
        internal void Save(int cust_id = 0) {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();

            // We are going to make an attempt at saving the Address record

            this.cust_id = cust_id;

            // First let's Sanitize our Addresses
            UDF.Sanitize(this,new string[]{"street2", "state1","latitude","longitude"});

            Address new_address = this;

            db.Addresses.InsertOnSubmit(new_address);
            db.SubmitChanges();
            this.ID = new_address.ID;

        }
Example #8
0
 internal void MatchOrSave() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Address address = (from a in db.Addresses
                         where a.cust_id.Equals(this.cust_id) && a.first.ToLower().Trim().Equals(this.first.ToLower().Trim()) &&
                         a.last.ToLower().Trim().Equals(this.last.ToLower().Trim()) &&
                         a.street1.ToLower().Trim().Equals(this.street1.ToLower().Trim()) &&
                         a.street2.ToLower().Trim().Equals(this.street2.ToLower().Trim()) &&
                         a.city.ToLower().Trim().Equals(this.city.ToLower().Trim()) &&
                         a.state.Equals(this.state) &&
                         a.postal_code.ToLower().Trim().Equals(this.postal_code.ToLower().Trim())
                         select a).FirstOrDefault();
     if(address != null && address.ID > 0) {
         this.ID = address.ID;
     } else {
         db.Addresses.InsertOnSubmit(this);
         db.SubmitChanges();
     }
 }
Example #9
0
 public void Empty()
 {
     if (this.payment_id == 0) {
         if (this.cust_id > 0) {
             EcommercePlatformDataContext db = new EcommercePlatformDataContext();
             List<CartItem> items = new List<CartItem>();
             try {
                 items = db.CartItems.Where(x => x.order_id == this.ID).ToList<CartItem>();
                 db.CartItems.DeleteAllOnSubmit(items);
                 db.SubmitChanges();
             } catch { };
         }
         foreach (CartItem i in this.CartItems) {
             this.CartItems.Remove(i);
         }
     } else {
         UDF.ExpireCart(this.cust_id);
     }
 }
Example #10
0
        public void Add(HttpContext ctx, int partID = 0, int quantity = 1) {
            if (this.payment_id == 0) {
                APIPart part = CURTAPI.GetPart(partID);
                string upcval = part.attributes.Where(x => x.key.ToLower().Equals("upc")).Select(x => x.value).FirstOrDefault();
                string weight = part.attributes.Where(x => x.key.ToLower().Equals("weight")).Select(x => x.value).FirstOrDefault();
                CartItem i = new CartItem(partID, quantity, Convert.ToDecimal(part.listPrice.Replace("$", "")), part.shortDesc, upcval, Convert.ToDecimal(weight));

                EcommercePlatformDataContext db = new EcommercePlatformDataContext();
                try {
                    CartItem item = db.CartItems.Where(x => x.partID == partID).Where(x => x.order_id == this.ID).First<CartItem>();
                    item.quantity += quantity;
                } catch {
                    i.order_id = this.ID;
                    db.CartItems.InsertOnSubmit(i);
                };
                db.SubmitChanges();
                clearShippingType();
            } else {
                UDF.ExpireCart(ctx,this.cust_id);
            }
        }
Example #11
0
 internal void AddPayment(string type, string confirmKey, string status) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     PaymentType ptype = db.PaymentTypes.Where(x => x.name.ToLower() == type.ToLower()).FirstOrDefault();
     Payment p = new Payment {
         type = ptype.ID,
         created = DateTime.UtcNow,
         confirmationKey = confirmKey,
         status = status
     };
     db.Payments.InsertOnSubmit(p);
     db.SubmitChanges();
     Cart c = db.Carts.Where(x => x.ID == this.ID).FirstOrDefault<Cart>();
     c.payment_id = p.ID;
     db.SubmitChanges();
     this._payment_id = p.ID;
 }
Example #12
0
 internal void SetShipping(int id = 0) {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         if (id == 0) {
             id = db.Customers.Where(x => x.ID == this.cust_id).Select(x => x.shippingID).First();
         }
         Cart c = db.Carts.Where(x => x.ID == this.ID).First<Cart>();
         c.ship_to = id;
         db.SubmitChanges();
         this._ship_to = id;
         setHandlingFee();
     } catch (Exception) { }
     GetShipping();
 }
Example #13
0
 public void clearShippingType() {
     if (this.cust_id > 0) {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         try {
             Cart cart = db.Carts.Where(x => x.ID == this.ID).First<Cart>();
             cart.shipping_price = 0;
             cart.shipping_type = null;
             db.SubmitChanges();
         } catch { }
     }
     this.shipping_type = null;
     this.shipping_price = 0;
 }
Example #14
0
 public void setShippingType(string shipping_type, decimal shipping_price) {
     if (this.cust_id > 0) {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         try {
             Cart cart = db.Carts.Where(x => x.ID == this.ID).First<Cart>();
             cart.shipping_price = shipping_price;
             cart.shipping_type = shipping_type;
             db.SubmitChanges();
         } catch { }
     }
     this.shipping_type = shipping_type;
     this.shipping_price = shipping_price;
 }
Example #15
0
        internal void ResetPassword() {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            string orig_pass = this.password;
            try {
                PasswordGenerator pw = new PasswordGenerator();
                string new_pass = pw.Generate();
                Settings settings = new Settings();

                string[] tos = { this.email };
                StringBuilder sb = new StringBuilder();

                sb.Append("<p>A new password has been generated for an account with this e-mail address from <a href='" + settings.Get("SiteURL") + "' title='" + settings.Get("SiteName") + "'>" + settings.Get("SiteName") + "</a>.</p>");
                sb.Append("<hr />");
                sb.Append("<p>To <a href='" + settings.Get("SiteURL") + "' title='Login' target='_blank'>login</a> to " + settings.Get("SiteName") + ", please use the information provided below.</p>");
                sb.Append("<span>The new password is: <strong>" + new_pass + "</strong></span><br />");
                sb.Append("<hr /><br />");
                sb.Append("<p style='font-size:11px'>If you feel this was a mistake please disregard this e-mail.</p>");

                UDF.SendEmail(tos, "New password for " + settings.Get("SiteName"), true, sb.ToString());
                Customer c = db.Customers.Where(x => x.ID.Equals(this.ID)).First<Customer>();
                c.password = UDF.EncryptString(new_pass);
            } catch {}
            db.SubmitChanges();
        }
Example #16
0
 public void Void() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Cart c = db.Carts.Where(x => x.ID == this.ID).First<Cart>();
     c.voided = true;
     db.SubmitChanges();
 }
Example #17
0
 public void RemoveCart() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Cart i = db.Carts.Where(x => x.ID.Equals(this.ID)).First<Cart>();
     db.Carts.DeleteOnSubmit(i);
     db.SubmitChanges();
 }
Example #18
0
        internal void SaveAddresses(Address billing, Address shipping) {
            
            this.billingID = billing.ID;
            this.shippingID = shipping.ID;

            Customer tmp = new Customer();
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            tmp = db.Customers.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<Customer>();
            tmp.billingID = this.billingID;
            tmp.shippingID = this.shippingID;
            db.SubmitChanges();
        }
Example #19
0
 internal void ClearAddress(int id) {
     if (this.billingID == id || this.shippingID == id) {
         Customer tmp = new Customer();
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         tmp = db.Customers.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<Customer>();
         if (tmp.billingID == id) {
             tmp.billingID = 0;
         }
         if (tmp.shippingID == id) {
             tmp.shippingID = 0;
         }
         db.SubmitChanges();
     }
 }
Example #20
0
 internal void ValidateCreation() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     if (this.ID == 0 || this.validator == null) {
         throw new Exception("Invalid reference.");
     }
     Customer cust = db.Customers.Where(x => x.ID.Equals(this.ID) && x.validator.Equals(this.validator)).FirstOrDefault<Customer>();
     if (cust == null || cust.ID == 0) {
         throw new Exception("No Customer record found.");
     }
     cust.isValidated = 1;
     db.SubmitChanges();
 }
Example #21
0
        internal void Save() {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            Settings settings = new Settings();
            bool RequireCustomerActivation = true;
            if (settings.Get("RequireCustomerActivation") == "false") {
                RequireCustomerActivation = false;
            }

            // Make sure we don't have an account with this e-mail address
            Customer cust = this.GetCustomerByEmail();
            if (cust != null && cust.ID > 0) {
                throw new Exception("An account using the E-Mail address you provided already exists.");
            }

            // We are going to make an attempt at saving the Customer record

            Customer new_customer = new Customer {
                email = this.email,
                fname = this.fname,
                lname = this.lname,
                phone = this.phone,
                dateAdded = this.dateAdded,
                isSuspended = this.isSuspended,
                isValidated = this.isValidated,
                validator = this.validator,
                password = this.password,
                receiveNewsletter = this.receiveNewsletter,
                receiveOffers = this.receiveOffers,
            };

            if (!RequireCustomerActivation) {
                new_customer.isValidated = 1;
            }
            db.Customers.InsertOnSubmit(new_customer);
            db.SubmitChanges();
            this.ID = new_customer.ID;

            if (RequireCustomerActivation) {
                SendValidation();
            }
        }
Example #22
0
 internal void UpdatePaymentConfirmationCode(string confirmcode) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Payment p = db.Payments.Where(x => x.ID.Equals(this.payment_id)).FirstOrDefault<Payment>();
     p.confirmationKey = confirmcode;
     db.SubmitChanges();
 }
Example #23
0
 internal void UpdatePayment(string status) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Payment p = db.Payments.Where(x => x.ID.Equals(this.payment_id)).FirstOrDefault<Payment>();
     p.status = status;
     db.SubmitChanges();
     string[] voidstatuses = {"CANCELLED","CANCELLED_BY_GOOGLE"};
     if(voidstatuses.Contains(status.ToUpper())) {
         // void order
         Void();
         // send notification about voided order
         SendCancelNotice();
     }
 }
Example #24
0
 public void setHandlingFee() {
     decimal fee = 0;
     if (this.cust_id > 0) {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         try {
             Cart cart = db.Carts.Where(x => x.ID == this.ID).First<Cart>();
             Address shipping = db.Addresses.Where(x => x.ID.Equals(this.ship_to)).FirstOrDefault<Address>();
             //cart.BindAddresses();
             if (shipping != null && shipping.State1 != null) {
                 fee = shipping.State1.handlingFee;
             }
             cart.handling_fee = fee;
             db.SubmitChanges();
         } catch { }
     }
     this.handling_fee = fee;
 }
Example #25
0
 internal void MatchOrSave()
 {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     try {
         Address address = (from a in db.Addresses
                            where a.first.ToLower().Trim().Equals(this.first.ToLower().Trim()) &&
                            a.last.ToLower().Trim().Equals(this.last.ToLower().Trim()) &&
                            a.street1.ToLower().Trim().Equals(this.street1.ToLower().Trim()) &&
                            a.street2.ToLower().Trim().Equals(this.street2.ToLower().Trim()) &&
                            a.city.ToLower().Trim().Equals(this.city.ToLower().Trim()) &&
                            a.state.Equals(this.state) &&
                            a.postal_code.ToLower().Trim().Equals(this.postal_code.ToLower().Trim())
                            select a).First();
         this.ID = address.ID;
     } catch {
         this.residential = true;
         this.cust_id = 0;
         db.Addresses.InsertOnSubmit(this);
         db.SubmitChanges();
     }
 }
Example #26
0
 internal void SetShippingDefaultAddress(int id) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Customer cust = new Customer();
     cust = db.Customers.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<Customer>();
     cust.shippingID = id;
     db.SubmitChanges();
     this.shippingID = id;
 }
Example #27
0
        internal void SetTax() {
            decimal tax = 0;
            tax = Math.Round((this.GetSubTotal() * (this.Shipping.State1.taxRate / 100)),2);

            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            Cart c = db.Carts.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<Cart>();
            c.tax = tax;
            db.SubmitChanges();

            this.tax = tax;
        }
Example #28
0
 public void UpdateCart(HttpContext ctx, int cust_id = 0) {
     if (this.payment_id == 0) {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         Cart c = db.Carts.Where(x => x.ID.Equals(this.ID)).First<Cart>();
         c.cust_id = cust_id;
         try {
             Customer cust = db.Customers.Where(x => x.ID == cust_id).First<Customer>();
             c.ship_to = cust.shippingID;
             c.bill_to = cust.billingID;
         } catch { }
         db.SubmitChanges();
     } else {
         UDF.ExpireCart(ctx, this.cust_id);
     }
 }
Example #29
0
 public void SetStatus(int statusID) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     OrderHistory status = new OrderHistory {
         dateAdded = DateTime.UtcNow,
         changedBy = "System",
         orderID = this.ID,
         statusID = statusID
     };
     db.OrderHistories.InsertOnSubmit(status);
     db.SubmitChanges();
 }
Example #30
0
 public Cart Save() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     try {
         Cart c = new Cart {
             cust_id = 0,
             date_created = DateTime.UtcNow,
             shipping_price = 0
         };
         db.Carts.InsertOnSubmit(c);
         db.SubmitChanges();
         return c;
     } catch { };
     return this;
 }