Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
 internal List<Address> GetAddresses()
 {
     List<Address> addresses = new List<Address>();
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     addresses = db.Addresses.Where(x => x.cust_id.Equals(this.ID) && x.active).ToList<Address>();
     return addresses;
 }
Exemplo n.º 4
0
 internal int Count()
 {
     int custs = 0;
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     custs = db.Customers.Count();
     return custs;
 }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
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();
 }
Exemplo n.º 7
0
 internal List<Banner> GetAll()
 {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     List<Banner> banners = new List<Banner>();
     banners = db.Banners.ToList<Banner>();
     return banners;
 }
Exemplo n.º 8
0
 public List<CartItem> GetParts()
 {
     string partlist = "";
     List<int> items = new List<int>();
     if (this.cust_id > 0) {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         items = db.CartItems.Where(x => x.order_id == this.ID).Select(x => x.partID).ToList();
     } else {
         items = CartItems.Select(x => x.partID).ToList();
     }
     foreach (int item in items) {
         if (partlist != "") partlist += ",";
         partlist += item.ToString();
     }
     List<APIPart> parts = new List<APIPart>();
     if (partlist.Length > 0) {
         parts = CURTAPI.GetPartsByList(partlist);
         if (parts.Count > 0) {
             foreach (CartItem item in this.CartItems) {
                 item.apipart = parts.Find(x => x.partID == item.partID);
             };
         }
     }
     return this.CartItems.ToList<CartItem>();
 }
Exemplo n.º 9
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();
 }
Exemplo n.º 10
0
 internal IOrderedQueryable<InvoiceCount> GetAll() {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         return db.Invoices.GroupBy(dates => dates.created.Date, invoices => invoices.created, (dates, invoices) => new InvoiceCount { invoiceDate = dates, invoiceCount = invoices.Count() }).OrderByDescending(x => x.invoiceDate);
     } catch (Exception) {
         return null;
     }
 }
Exemplo n.º 11
0
 internal List<Invoice> GetAllUnprinted() {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         return db.Invoices.Where(x => !x.printed).ToList<Invoice>();
     } catch (Exception) {
         return new List<Invoice>();
     }
 }
Exemplo n.º 12
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>();
     }
 }
Exemplo n.º 13
0
 internal List<Invoice> GetAllByDate(DateTime date) {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         return db.Invoices.Where(x => x.created.Date.Equals(date.Date)).OrderBy(x => x.number).ToList<Invoice>();
     } catch (Exception) {
         return new List<Invoice>();
     }
 }
Exemplo n.º 14
0
 internal static List<FAQ> GetAll() {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         return db.FAQs.OrderBy(x => x.order).ToList<FAQ>();
     } catch (Exception) {
         return new List<FAQ>();
     }
 }
Exemplo n.º 15
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();
 }
Exemplo n.º 16
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");
     }
 }
Exemplo n.º 17
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();
 }
Exemplo n.º 18
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");
     }
 }
Exemplo n.º 19
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();
 }
Exemplo n.º 20
0
 internal void Get() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     FAQ tmp = db.FAQs.Where(x => x.ID.Equals(this._ID)).FirstOrDefault<FAQ>();
     if (tmp != null && tmp.ID > 0) {
         this.ID = tmp.ID;
         this.question = tmp.question;
         this.answer = tmp.answer;
         this.order = tmp.order;
         this.topic = tmp.topic;
     }
 }
Exemplo n.º 21
0
 internal ContactInquiry Get() {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         if (this._ID > 0) {
             return db.ContactInquiries.Where(x => x.ID.Equals(this._ID)).FirstOrDefault<ContactInquiry>();
         }
         return new ContactInquiry();
     } catch (Exception) {
         return new ContactInquiry();
     }
 }
Exemplo n.º 22
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();
        }
Exemplo n.º 23
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;
     }
 }
Exemplo n.º 24
0
        internal void Get()
        {
            Banner tmp = new Banner();
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();

            tmp = db.Banners.Where(x => x.ID.Equals(this.ID)).FirstOrDefault<Banner>();
            this.image = tmp.image;
            this.title = tmp.title;
            this.body = tmp.body;
            this.link = tmp.link;
            this.order = tmp.order;
            this.isVisible = tmp.isVisible;
        }
Exemplo n.º 25
0
 public int getCount()
 {
     int count = 0;
     if (this.cust_id > 0) {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         try {
             count = db.CartItems.Where(x => x.order_id == this.ID).Sum(x => x.quantity);
         } catch { }
     } else {
         count = this.CartItems.Sum(x => x.quantity);
     }
     return count;
 }
Exemplo n.º 26
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;
 }
Exemplo n.º 27
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;
 }
Exemplo n.º 28
0
 public bool Preview(int id) {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     Theme theme = db.Themes.Where(x => x.ID.Equals(id)).FirstOrDefault();
     if (theme != null && theme.ID > 0) {
         // adjust cookies so theme shows up immediately
         ClearThemeSession(theme.ID);
         HttpCookie activeTheme = new HttpCookie("activetheme");
         activeTheme = new HttpCookie("activetheme");
         activeTheme.Value = theme.ID.ToString();
         activeTheme.Expires = DateTime.Now.AddMinutes(5);
         HttpContext.Current.Response.Cookies.Add(activeTheme);
         return true;
     }
     return false;
 }
Exemplo n.º 29
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);
     }
 }
Exemplo n.º 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();
     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();
     }
 }