Пример #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();
 }
Пример #2
0
        internal void Save()
        {
            // Run our faq through the Sanitizer, just to make sure it doesn't have a dirty mouth
            UDF.Sanitize(this, new string[] { "faqtopic" });

            // Conntect to db
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();

            if (this.ID == 0) { // Insert new

                /******
                 * I'd like to be able to do a comparison of the submitted question to make sure don't have this question already, but f*****g
                 * SQL Server won't allow us to do a comparison on Text data types. Bastards!!
                 *****/
                // Make sure we don't have a faq with the same question
                /*FAQ tmp = db.FAQs.Where(x => x.question.ToLower().Equals(this._question.ToLower())).FirstOrDefault<FAQ>();
                if (tmp != null && tmp._ID > 0) {
                    throw new Exception("Question exists, try again.");
                }*/

                this._order = db.FAQs.Select(x => x.order).Max();
                db.FAQs.InsertOnSubmit(this);
            } else { // Update existing
                FAQ exist = db.FAQs.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<FAQ>();
                if (exist == null || exist.ID == 0) {
                    throw new Exception("Failed to reference to existing question for identifier: " + this.ID);
                }
                exist.question = this.question;
                exist.answer = this.answer;
                exist.order = this.order;
                exist.topic = this.topic;
            }
            db.SubmitChanges();
        }
Пример #3
0
 internal void Delete()
 {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Banner tmp = db.Banners.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<Banner>();
     db.Banners.DeleteOnSubmit(tmp);
     db.SubmitChanges();
 }
Пример #4
0
 public void SaveRate(decimal taxRate)
 {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     State state = db.States.Where(x => x.stateID.Equals(this.stateID)).First<State>();
     state.taxRate = taxRate;
     db.SubmitChanges();
 }
Пример #5
0
 internal void Delete() {
     if (this._ID == 0) {
         throw new Exception("Inavlid refernce to contact type, must set the ContactType ID field.");
     }
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     ContactType type = db.ContactTypes.Where(x => x.ID.Equals(this._ID)).FirstOrDefault<ContactType>();
     db.ContactTypes.DeleteOnSubmit(type);
     db.SubmitChanges();
 }
Пример #6
0
 internal void Delete() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     if (this._ID > 0) {
         ContactInquiry inq = db.ContactInquiries.Where(x => x.ID.Equals(this._ID)).FirstOrDefault<ContactInquiry>();
         db.ContactInquiries.DeleteOnSubmit(inq);
         db.SubmitChanges();
     } else {
         throw new Exception("Invalid reference to inquiry");
     }
 }
Пример #7
0
 internal void Paid() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Invoice i = db.Invoices.Where(x => x.id == this.id).FirstOrDefault<Invoice>();
     if (i.paid) {
         i.paid = false;
     } else {
         i.paid = true;
     }
     db.SubmitChanges();
 }
Пример #8
0
 internal void MarkResponded() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     if (this._ID > 0) {
         ContactInquiry inq = db.ContactInquiries.Where(x => x.ID.Equals(this._ID)).FirstOrDefault<ContactInquiry>();
         inq.followedUp = 1;
         db.SubmitChanges();
     } else {
         throw new Exception("Invalid reference to inquiry");
     }
 }
Пример #9
0
        public void Run()
        {
            string url = this.url;
            url += "?lastRan=" + ((this.lastRan != null) ? String.Format("{0:MMddyyyyHHmmss}", this.lastRan) : "");
            WebClient wc = new WebClient();
            wc.Proxy = null;
            wc.DownloadString(url);

            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            ScheduledTask t = db.ScheduledTasks.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<ScheduledTask>();
            t.lastRan = DateTime.Now;
            db.SubmitChanges();
        }
Пример #10
0
 internal bool Delete(int id = 0) {
     bool success = false;
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     using (TransactionScope ts = new TransactionScope()) {
         try {
             Address a = db.Addresses.Where(x => x.ID == id).Where(x => x.active == true).First<Address>();
             a.active = false;
             db.SubmitChanges();
             success = true;
             ts.Complete();
         } catch { }
     }
     return success;
 }
Пример #11
0
 public bool Delete(int id) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Theme theme = db.Themes.Where(x => x.ID.Equals(id)).FirstOrDefault();
     if (theme != null && theme.ID > 0) {
         foreach(ThemeFile file in theme.ThemeFiles) {
             new ThemeFile().Delete(file.ID);
         }
         db.ThemeFiles.DeleteAllOnSubmit(theme.ThemeFiles);
         db.Themes.DeleteOnSubmit(theme);
         db.SubmitChanges();
         return true;
     }
     return false;
 }
Пример #12
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();
     Address a = db.Addresses.Where(x => x.ID.Equals(this.ID)).FirstOrDefault();
     if (a != null && a.ID > 0) {
         a.first = first;
         a.last = last;
         a.street1 = street1;
         a.street2 = street2;
         a.city = city;
         a.state = state_id;
         a.postal_code = zip;
         a.residential = residential;
         db.SubmitChanges();
     }
 }
Пример #13
0
 public void Empty()
 {
     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);
     }
 }
Пример #14
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;

        }
Пример #15
0
 public void Save(string name, string screenshot = "") {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Theme theme = new Theme();
     if (this.ID > 0)
         theme = db.Themes.Where(x => x.ID.Equals(this.ID)).FirstOrDefault();
     else
         theme = new Theme();
     theme.name = name;
     theme.screenshot = (string.IsNullOrWhiteSpace(screenshot)) ? null : screenshot;
     if (theme.ID == 0) {
         theme.dateAdded = DateTime.UtcNow;
         theme.active = false;
         db.Themes.InsertOnSubmit(theme);
     }
     db.SubmitChanges();
     this.ID = theme.ID;
 }
Пример #16
0
 public void Save() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     OrderEDI edi = db.OrderEDIs.Where(x => x.orderID.Equals(this.orderID)).FirstOrDefault();
     if (edi != null && edi.ID > 0) {
         edi.filename = this.filename;
         edi.editext = this.editext;
         edi.dateGenerated = DateTime.UtcNow;
     } else {
         edi = new OrderEDI {
             orderID = this.orderID,
             filename = this.filename,
             editext = this.editext,
             dateGenerated = DateTime.UtcNow,
             dateAcknowledged = this.dateAcknowledged
         };
         db.OrderEDIs.InsertOnSubmit(edi);
     }
     db.SubmitChanges();
 }
Пример #17
0
        internal void Add() {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();

            // Validate fields
            if (this._label == null || this._label.Trim().Length == 0) {
                throw new Exception("Label cannot be empty.");
            }
            if (this._email == null || this._email.Trim().Length == 0) {
                throw new Exception("E-Mail cannot be empty.");
            }

            // Make sure we don't have a label with the same title
            ContactType exist = db.ContactTypes.Where(x => x.label.ToLower().Equals(this._label.Trim().ToLower())).FirstOrDefault<ContactType>();
            if (exist != null && exist.ID > 0) {
                throw new Exception("A contact type with this label exists.");
            }

            db.ContactTypes.InsertOnSubmit(this);
            db.SubmitChanges();
        }
Пример #18
0
        internal void Save()
        {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            Banner tmp = db.Banners.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<Banner>();
            if (tmp == null) {
                tmp = new Banner();
            }
            tmp.image = this.image;
            tmp.title = this.title;
            tmp.body = this.body;
            tmp.link = this.link;
            tmp.order = this.order;
            tmp.isVisible = this.isVisible;
            //tmp.OrganizeSort();

            if (this.ID == 0) {
                db.Banners.InsertOnSubmit(tmp);
            }
            db.SubmitChanges();
            this._ID = tmp.ID;
        }
Пример #19
0
 public CartItem Add(int partID = 0, int quantity = 1)
 {
     APIPart part = CURTAPI.GetPart(partID);
     string upcval = part.attributes.Where(x => x.key.ToLower().Equals("upc")).Select(x => x.value).FirstOrDefault();
     CartItem i = new CartItem(partID, quantity, Convert.ToDecimal(part.listPrice.Replace("$", "")), part.shortDesc, upcval);
     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();
     if (this.CartItems.Any(item => item.partID == i.partID)) {
         this.CartItems.Where(x => x.partID.Equals(partID)).FirstOrDefault<CartItem>().quantity += quantity;
     } else {
         this.CartItems.Add(i);
     }
     return i;
 }
Пример #20
0
        private void OrganizeSort()
        {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();

            int max_order = 0;
            int min_order = 0;
            try {
                max_order = db.Banners.Select(x => x.order).Max<int>();
            } catch (Exception) { }
            try {
                min_order = db.Banners.Select(x => x.order).Min<int>();
            } catch (Exception) { }
            if (this.order <= max_order) {
                // Get all the Banners with a sort higher than this one.
                List<Banner> banners = db.Banners.Where(x => x.order >= this.order && x.ID != this.ID).ToList<Banner>();
                foreach (Banner b in banners) {

                    b.order = b.order + 1;
                }
                db.SubmitChanges();
            }
        }
Пример #21
0
        public bool Activate(int id) {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            Theme theme = db.Themes.Where(x => x.ID.Equals(id)).FirstOrDefault();
            if (theme != null && theme.ID > 0) {
                List<Theme> themes = db.Themes.Where(x => x.active == true).ToList();
                foreach (Theme t in themes) {
                    t.active = false;
                }
                theme.active = true;
                db.SubmitChanges();

                ClearThemeSession(theme.ID);

                // adjust cookies so theme shows up immediately
                HttpCookie activeTheme = new HttpCookie("activetheme");
                activeTheme = new HttpCookie("activetheme");
                activeTheme.Value = theme.ID.ToString();
                activeTheme.Expires = DateTime.Now.AddHours(1);
                HttpContext.Current.Response.Cookies.Add(activeTheme);
                return true;
            }
            return false;
        }
Пример #22
0
 public Theme Duplicate(int id) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Theme theme = db.Themes.Where(x => x.ID.Equals(id)).FirstOrDefault();
     Theme newtheme = new Theme();
     if (theme != null && theme.ID > 0) {
         newtheme = new Theme {
             screenshot = theme.screenshot,
             name = "Copy of " + theme.name,
             active = false,
             dateAdded = DateTime.UtcNow
         };
         db.Themes.InsertOnSubmit(newtheme);
         db.SubmitChanges();
         foreach (ThemeFile file in theme.ThemeFiles) {
             file.Duplicate(newtheme.ID);
         }
     }
     return newtheme;
 }
Пример #23
0
        internal void Save()
        {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            PasswordGenerator pw = new PasswordGenerator();
                string new_pass = pw.Generate();

            // 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,
            };

            db.Customers.InsertOnSubmit(new_customer);
            db.SubmitChanges();
            this.ID = new_customer.ID;

            SendNotification();
        }
Пример #24
0
 internal void Print()
 {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Invoice i = db.Invoices.Where(x => x.id == this.id).FirstOrDefault<Invoice>();
     i.printed = true;
     db.SubmitChanges();
 }
Пример #25
0
        internal void Delete() {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();

            // We need to get all the questions that are tied to this topic and set them to zero
            List<FAQ> faqs = db.FAQs.Where(x => x.topic.Equals(this._ID)).ToList<FAQ>();
            foreach (FAQ faq in faqs) {
                faq.topic = 0;
            }

            // Get the topic to be deleted
            FaqTopic tmp = db.FaqTopics.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<FaqTopic>();

            db.FaqTopics.DeleteOnSubmit(tmp);
            db.SubmitChanges();
        }
Пример #26
0
        internal void Save() {

            // Run our topic through the Sanitizer and clean it up
            UDF.Sanitize(this, new string[]{""});

            // Connect to db
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            
            if (this._ID == 0) { // Insert new

                // Make sure we don't have topic with the same title
                FaqTopic tmp = db.FaqTopics.Where(x => x.topic.ToLower().Equals(this._topic.ToLower())).FirstOrDefault<FaqTopic>();
                if (tmp != null && tmp.ID > 0) {
                    throw new Exception("Topic exists, try again.");
                }
                this._dateAdded = DateTime.UtcNow;
                db.FaqTopics.InsertOnSubmit(this);

            } else { // Update existing
                FaqTopic exist = db.FaqTopics.Where(x => x.ID.Equals(this._ID)).FirstOrDefault<FaqTopic>();
                if (exist == null || exist.ID == 0) {
                    throw new Exception("Failed to reference to existing topic for identifier: " + this._ID);
                }
                exist.topic = this._topic;
            }
            db.SubmitChanges();
        }
Пример #27
0
 internal void ToggleSuspended()
 {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Customer tmp = db.Customers.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<Customer>();
     if (tmp.isSuspended == 0) {
         tmp.isSuspended = 1;
     } else {
         tmp.isSuspended = 0;
     }
     db.SubmitChanges();
 }
Пример #28
0
        internal void Update(string email, string fname, string lname)
        {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();

            Customer c = db.Customers.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<Customer>();
            // Make sure we don't have an account with this e-mail address
            if (email != this.email) {
                // Make sure we don't have an account with this e-mail address
                if (Customer.CheckCustomerEmail(email)) {
                    throw new Exception("An account using the E-Mail address you provided already exists.");
                }
                c.email = email;
            }

            // We are going to make an attempt at saving the Customer record
            if (fname != this.fname) {
                c.fname = fname;
            }
            if (lname != this.lname) {
                c.lname = lname;
            }

            db.SubmitChanges();
        }
Пример #29
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();
        }
Пример #30
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();
 }