Esempio n. 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();
     }
 }
Esempio n. 3
0
 internal void ValidateCurrentPassword(string pass) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Customer c = db.Customers.Where(x => x.ID.Equals(this.ID)).First<Customer>();
     if (c.password != UDF.EncryptString(pass)) {
         throw new Exception("The current password you entered was incorrect. Try Again");
     }
 }
        public DistributionCenter GetNearest(Address address) {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            DistributionCenter distcenter = new DistributionCenter();
            try {
                double earth = 3963.1676; // radius of Earth in miles
                DCList d = (from dc in db.DistributionCenters
                            where dc.State1.countryID == address.State1.countryID
                            select new DCList {
                                ID = dc.ID,
                                distance = earth * (
                                                    2 * Math.Atan2(
                                                        Math.Sqrt((Math.Sin((Convert.ToDouble(dc.Latitude - address.latitude) * (Math.PI / 180)) / 2) * Math.Sin((Convert.ToDouble(dc.Latitude - address.latitude) * (Math.PI / 180)) / 2)) + ((Math.Sin((Convert.ToDouble(dc.Longitude - address.longitude) * (Math.PI / 180)) / 2)) * (Math.Sin((Convert.ToDouble(dc.Longitude - address.longitude) * (Math.PI / 180)) / 2))) * Math.Cos(Convert.ToDouble(address.latitude) * (Math.PI / 180)) * Math.Cos(Convert.ToDouble(dc.Latitude) * (Math.PI / 180))),
                                                        Math.Sqrt(1 - ((Math.Sin((Convert.ToDouble(dc.Latitude - address.latitude) * (Math.PI / 180)) / 2) * Math.Sin((Convert.ToDouble(dc.Latitude - address.latitude) * (Math.PI / 180)) / 2)) + ((Math.Sin((Convert.ToDouble(dc.Longitude - address.longitude) * (Math.PI / 180)) / 2)) * (Math.Sin((Convert.ToDouble(dc.Longitude - address.longitude) * (Math.PI / 180)) / 2))) * Math.Cos(Convert.ToDouble(address.latitude) * (Math.PI / 180)) * Math.Cos(Convert.ToDouble(dc.Latitude) * (Math.PI / 180))))
                                                    )
                                                )
                            }).OrderBy(x => x.distance).First<DCList>();

                distcenter = db.DistributionCenters.Where(x => x.ID == d.ID).First<DistributionCenter>();
            } catch {
                DCList d = (from dc in db.DistributionCenters
                            where dc.State1.countryID == address.State1.countryID
                            select new DCList {
                                ID = dc.ID,
                                distance = 0
                            }).OrderBy(x => x.distance).First<DCList>();
                distcenter = db.DistributionCenters.Where(x => x.ID == d.ID).First<DistributionCenter>();
            };
            return distcenter;
        }
Esempio n. 5
0
 internal static List<FaqTopic> GetAll() {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         return db.FaqTopics.OrderBy(x => x.topic).ToList<FaqTopic>();
     } catch (Exception) {
         return new List<FaqTopic>();
     }
 }
Esempio n. 6
0
 public static List<Banner> GetRandomBanners(int count = 5) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     List<Banner> banners = new List<Banner>();
     banners = db.Banners.Where(x => x.isVisible.Equals(1)).ToList<Banner>();
     banners = UDF.Shuffle<Banner>(banners);
     banners = banners.Take(count).ToList<Banner>();
     return banners;
 }
Esempio n. 7
0
 internal void BindOrders()
 {
     if (this._ID > 0) {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         this.Orders = db.Carts.Where(x => x.cust_id.Equals(this.ID) && x.payment_id > 0).ToList<Cart>();
     } else {
         this.Orders = new List<Cart>();
     }
 }
Esempio n. 8
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();
 }
Esempio n. 9
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);
     }
 }
Esempio n. 10
0
        internal void BindAddresses()
        {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            if (this.billingID != 0) {
                this.Address = db.Addresses.Where(x => x.ID.Equals(this.billingID)).FirstOrDefault<Address>();
            }
            if (this.shippingID != 0) {
                this.Address1 = db.Addresses.Where(x => x.ID.Equals(this.shippingID)).FirstOrDefault<Address>();
            }

            this.Cart.BindAddresses();
        }
Esempio n. 11
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();
 }
Esempio n. 12
0
 public Cart GetByPayment(string confirmnumber)
 {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         Cart cart = (from c in db.Carts
                   join p in db.Payments on c.payment_id equals p.ID
                   where p.confirmationKey.Equals(confirmnumber)
                   select c).First();
         return cart;
     } catch (Exception) {
         return null;
     }
 }
Esempio n. 13
0
 public static bool CheckCustomerEmail(string email = null)
 {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     if (email == null) {
         return true;
     } else {
         bool exists = false;
         if(db.Customers.Where(x => x.email.Equals(email)).Count() > 0) {
             exists = true;
         }
         return exists;
     }
 }
Esempio n. 14
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);
     }
 }
Esempio n. 15
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();
     }
 }
Esempio n. 16
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;

        }
Esempio n. 17
0
 public static List<BasicCountry> GetBasic()
 {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     List<BasicCountry> countries = (from c in db.Countries
                                     select new BasicCountry {
                                         ID = c.ID,
                                         name = c.name,
                                         abbr = c.abbr,
                                         states = (from s in db.States
                                                     where s.countryID.Equals(c.ID)
                                                     select new BasicState {
                                                         stateID = s.stateID,
                                                         state = s.state1,
                                                         abbr = s.abbr
                                                     }).ToList<BasicState>()
                                     }).ToList<BasicCountry>();
     return countries;
 }
Esempio n. 18
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();
     }
 }
Esempio n. 19
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);
     }
 }
Esempio n. 20
0
 internal void Get() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     if (this.ID > 0) {
         FaqTopic tmp = db.FaqTopics.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<FaqTopic>();
         this.ID = tmp.ID;
         this.topic = tmp.topic;
         this.dateAdded = tmp.dateAdded;
         this.FAQs = tmp.FAQs;
     } else if (this.topic != null && this.topic.Length > 0) {
         FaqTopic tmp = db.FaqTopics.Where(x => x.topic.Equals(this.topic)).FirstOrDefault<FaqTopic>();
         this.ID = tmp.ID;
         this.topic = tmp.topic;
         this.dateAdded = tmp.dateAdded;
         this.FAQs = tmp.FAQs;
     } else {
         this.ID = 0;
         this.topic = "";
         this.dateAdded = DateTime.UtcNow;
     }
 }
Esempio n. 21
0
        public int getTheme(HttpContext ctx) {
            HttpCookie activeTheme = new HttpCookie("activetheme");
            activeTheme = ctx.Request.Cookies.Get("activetheme");
            int themeid = 0;

            if (activeTheme != null && activeTheme.Value != null) {
                int inttest;
                if (int.TryParse(activeTheme.Value, out inttest)) {
                    themeid = Convert.ToInt32(activeTheme.Value);
                }
            } else {
                EcommercePlatformDataContext db = new EcommercePlatformDataContext();
                themeid = db.Themes.Where(x => x.active.Equals(true)).Select(x => x.ID).FirstOrDefault();
                activeTheme = new HttpCookie("activetheme");
                activeTheme.Value = themeid.ToString();
                activeTheme.Expires = DateTime.Now.AddHours(1);
                ctx.Response.Cookies.Add(activeTheme);
            }
            return themeid;
        }
Esempio n. 22
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();
            }
        }
Esempio n. 23
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);
            }
        }
Esempio n. 24
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();
            }

        }
Esempio n. 25
0
 private Dictionary<int,List<ThemeFile>> getBaseFiles(HttpContext ctx) {
     Dictionary<int, List<ThemeFile>> files = new Dictionary<int, List<ThemeFile>>();
     List<ThemeFile> basefiles = new List<ThemeFile>();
     int themeID = getTheme(ctx);
     string keyname = themeID + "basefiles";
     if (ctx.Session[keyname] != null && themeID == getSessionTheme(ctx)) {
         basefiles = (List<ThemeFile>)ctx.Session[keyname];
     } else {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         basefiles = db.Themes.Where(x => x.ID.Equals(themeID)).SelectMany(x => x.ThemeFiles.Where(y => y.ThemeArea.controller.ToLower().Equals("base"))).OrderBy(x => x.ThemeFileTypeID).ThenBy(x => x.renderOrder).ToList();
         ctx.Session[keyname] = basefiles;
     }
     foreach(ThemeFile file in basefiles) {
         if(!files.Keys.Contains(file.ThemeFileTypeID)) {
             List<ThemeFile> sublist = new List<ThemeFile>();
             sublist.Add(file);
             files.Add(file.ThemeFileTypeID,sublist);
         } else {
             files[file.ThemeFileTypeID].Add(file);
         }
     }
     return files;
 }
Esempio n. 26
0
 public static List<Banner> GetBanners() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     List<Banner> banners = new List<Banner>();
     banners = db.Banners.Where(x => x.isVisible.Equals(1)).OrderBy(x => x.order).ToList<Banner>();
     return banners;
 }
Esempio n. 27
0
        internal void SendCancelNotice() {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            Payment payment = this.getPayment();

            string toemail = db.Customers.Where(x => x.ID == this.cust_id).Select(x => x.email).FirstOrDefault();
            StringBuilder sb = new StringBuilder();
            TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
            Settings settings = new Settings();

            string[] tos = { toemail };
            decimal total = 0;
            sb.Append("<html><body style=\"font-family: arial, helvetica,sans-serif;\">");
            sb.Append("<a href=\"" + settings.Get("SiteURL") + "\"><img src=\"" + settings.Get("EmailLogo") + "\" alt=\"" + settings.Get("SiteName") + "\" /></a>");
            sb.Append("<h2>We're Sorry</h2>");
            sb.Append("<hr />");
            sb.AppendFormat("<p>Your recent order placed with {0} has been cancelled. Google Checkout was unable to process your payment. The order details are listed below.</p>", settings.Get("SiteName"));
            sb.AppendFormat("<p><strong>Order ID:</strong> {0}<br />", this.payment_id);
            sb.AppendFormat("<strong>Paid By:</strong> {0} on {1}</p>", payment.PaymentTypes.name, String.Format("{0:M/d/yyyy} at {0:h:mm tt}", payment.created));
            sb.AppendFormat("<strong>Payment Status:</strong> {0}</p>", payment.status);
            sb.Append("<p style=\"font-size: 12px;\"><strong style=\"font-size: 14px;\">Billing Address:</strong><br />");
            sb.AppendFormat("{0} {1}<br />", this.Billing.first, this.Billing.last);
            sb.AppendFormat("{0}{1}<br />{2}, {3} {4}<br />{5}</p>", this.Billing.street1, this.Billing.street2, this.Billing.city, this.Billing.State1.abbr, this.Billing.postal_code, this.Billing.State1.Country.name);
            sb.Append("<p style=\"font-size: 12px;\"><strong style=\"font-size: 14px;\">Shipping Address:</strong><br />");
            sb.AppendFormat("{0} {1}<br />", this.Shipping.first, this.Shipping.last);
            sb.AppendFormat("{0}{1}<br />{2}, {3} {4}<br />{5}</p>", this.Shipping.street1, this.Shipping.street2, this.Shipping.city, this.Shipping.State1.abbr, this.Shipping.postal_code, this.Shipping.State1.Country.name);
            sb.Append("<table style=\"width: 100%;\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><thead><tr><th style=\"background-color: #343434; color: #fff;\">Item</th><th style=\"background-color: #343434; color: #fff;\">Quantity</th><th style=\"background-color: #343434; color: #fff;\">Price</th></tr></thead><tbody style=\"font-size: 12px;\">");
            foreach (CartItem item in this.CartItems) {
                sb.AppendFormat("<tr><td><a href=\"" + settings.Get("SiteURL") + "part/{0}\">{1}</a></td><td style=\"text-align:center;\">{2}</td><td style=\"text-align:right;\">{3}</td></tr>", item.partID, item.shortDesc, item.quantity, String.Format("{0:C}", item.price));
                total += (item.quantity * item.price);
            }
            sb.Append("</tbody><tfoot style=\"font-size: 12px;\">");
            sb.AppendFormat("<tr><td colspan=\"2\" style=\"border-top: 1px solid #222;text-align: right;\">({0}) Shipping:</td>", myTI.ToTitleCase(this.shipping_type.Replace("_", " ")));
            sb.AppendFormat("<td style=\"border-top: 1px solid #222;text-align:right;\">{0}</td></tr>", (this.shipping_price == 0) ? "Free" : String.Format("{0:C}", this.shipping_price));
            sb.Append("<tr><td colspan=\"2\" style=\"text-align: right;\"><strong>Total:<strong></td>");
            total += this.shipping_price;
            sb.AppendFormat("<td style=\"text-align:right;\"><strong>{0}</strong></td></tr>", String.Format("{0:C}", total));
            sb.Append("</tfoot></table>");
            sb.Append("<hr /><br />");
            sb.Append("<p style='font-size:11px'>We hope you come back and try your order again.  If you have any questions, please <a href='" + settings.Get("SiteURL") + "contact'>contact us</a>.</p>");
            sb.Append("</body></html>");
            UDF.SendEmail(tos, settings.Get("SiteName") + " Order Cancellation Notice", true, sb.ToString());
        }
Esempio n. 28
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;
        }
Esempio n. 29
0
 public int GetPaymentID() {
     int paymentID = 0;
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         paymentID = db.Carts.Where(x => x.ID.Equals(this.ID)).Select(x => x.payment_id).First();
     } catch {}
     return paymentID;
 }
Esempio n. 30
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();
 }