Ejemplo n.º 1
0
 public static string Delete(int id = 0) {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         List<BlogPost_BlogCategory> postcats = db.BlogPost_BlogCategories.Where(x => x.blogCategoryID.Equals(id)).ToList<BlogPost_BlogCategory>();
         db.BlogPost_BlogCategories.DeleteAllOnSubmit(postcats);
         db.SubmitChanges();
         BlogCategory category = (from c in db.BlogCategories
                                  where c.blogCategoryID.Equals(id)
                                  select c).FirstOrDefault<BlogCategory>();
         db.BlogCategories.DeleteOnSubmit(category);
         db.SubmitChanges();
         return "";
     } catch (Exception e) {
         return e.Message;
     }
 }
        public ActionResult AddTask(string name = "", string runtime = "", int interval = 0,string url = "")
        {
            try {
                if (url.Trim() == "") {
                    throw new Exception("Task must have a path.");
                }
                if (runtime.Trim() == "" && interval < 1) {
                    throw new Exception("Task must have a run time or an interval greater than 5 minutes.");
                }

                ScheduledTask s = new ScheduledTask {
                    name = name,
                    url = url
                };
                if (runtime.Trim() != "") {
                    DateTime rtime = Convert.ToDateTime(runtime).ToUniversalTime();
                    s.runtime = rtime;
                } else if(interval > 1) {
                    s.interval = interval;
                }
                EcommercePlatformDataContext db = new EcommercePlatformDataContext();
                db.ScheduledTasks.InsertOnSubmit(s);
                db.SubmitChanges();
            } catch {}
            return RedirectToAction("index");
        }
        internal static void ClearParents(int id)
        {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            List<ContentNesting> parents = new List<ContentNesting>();

            parents = db.ContentNestings.Where(x => x.pageID.Equals(id)).ToList<ContentNesting>();
            db.ContentNestings.DeleteAllOnSubmit<ContentNesting>(parents);
            db.SubmitChanges();
        }
Ejemplo n.º 4
0
        internal static void Delete(int id)
        {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            DistributionCenter dc = new DistributionCenter();
            dc = db.DistributionCenters.Where(x => x.ID.Equals(id)).FirstOrDefault<DistributionCenter>();

            db.DistributionCenters.DeleteOnSubmit(dc);
            db.SubmitChanges();
        }
Ejemplo n.º 5
0
 public ActionResult Delete(int id)
 {
     if (id > 0) {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         FTPFirewall ipaddress = db.FTPFirewalls.Where(x => x.ID.Equals(id)).FirstOrDefault<FTPFirewall>();
         db.FTPFirewalls.DeleteOnSubmit(ipaddress);
         db.SubmitChanges();
     }
     return RedirectToAction("Index");
 }
Ejemplo n.º 6
0
        internal static void Unsubscribe(Guid unsub) {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();

            if (unsub == null) { throw new Exception("Invalid reference to a subscription."); }
            Newsletter nw = db.Newsletters.Where(x => x.Unsubscribe.Equals(unsub)).FirstOrDefault<Newsletter>();
            if (nw == null) { throw new Exception("No subscription found."); }

            db.Newsletters.DeleteOnSubmit(nw);
            db.SubmitChanges();
        }
Ejemplo n.º 7
0
 public ActionResult FirstUse() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     try {
         Profile p = db.Profiles.Where(x => x.username.Equals("admin")).First<Profile>();
         if (p.password == "") {
             p.password = Crypto.EncryptString("admin");
             db.SubmitChanges();
         }
     } catch { };
     return RedirectToAction("Index");
 }
Ejemplo n.º 8
0
 public ActionResult Save() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     List<Setting> settinglist = db.Settings.ToList<Setting>();
     foreach (Setting s in settinglist) {
         try {
             s.value = Request.Form[s.name].Trim();
         } catch {};
     }
     db.SubmitChanges();
     return RedirectToAction("index");
 }
Ejemplo n.º 9
0
 public string DeleteGroup(int id = 0) {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         SettingGroup g = db.SettingGroups.Where(x => x.settingGroupID.Equals(id)).First<SettingGroup>();
         db.SettingGroups.DeleteOnSubmit(g);
         db.SubmitChanges();
         return "";
     } catch (Exception e) {
         return e.Message;
     }
 }
 public string DeleteTask(int id = 0)
 {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         ScheduledTask t = db.ScheduledTasks.Where(x => x.ID.Equals(id)).First<ScheduledTask>();
         db.ScheduledTasks.DeleteOnSubmit(t);
         db.SubmitChanges();
         return "";
     } catch (Exception e) {
         return e.Message;
     }
 }
        internal static ContentPage Add(ContentPage page)
        {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();

            if (page == null) { throw new Exception("Page is null."); }
            if (page.Title == null || page.Title.Length == 0) { throw new Exception("Page title is required."); }
            if (page.ID > 0) {
                ContentPage existing = db.ContentPages.Where(x => x.ID.Equals(page.ID)).FirstOrDefault<ContentPage>();
                existing.Title = page.Title;
                existing.content = page.content;
                existing.metaTitle = page.metaTitle;
                existing.metaDescription = page.metaDescription;
                existing.visible = page.visible;
                db.SubmitChanges();
                page = existing;
            } else {
                db.ContentPages.InsertOnSubmit(page);
                db.SubmitChanges();
            }
            return page;
        }
Ejemplo n.º 12
0
 public static void Delete(int id = 0)
 {
     try {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         List<BlogPost_BlogCategory> postcats = db.BlogPost_BlogCategories.Where(x => x.blogPostID.Equals(id)).ToList<BlogPost_BlogCategory>();
         db.BlogPost_BlogCategories.DeleteAllOnSubmit(postcats);
         BlogPost p = db.BlogPosts.Where(x => x.blogPostID == id).FirstOrDefault<BlogPost>();
         p.active = false;
         db.SubmitChanges();
     } catch (Exception e) {
         throw e;
     }
 }
Ejemplo n.º 13
0
 public static void Delete(int id = 0)
 {
     try
     {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         BlogPost p = db.BlogPosts.Where(x => x.blogPostID == id).FirstOrDefault<BlogPost>();
         p.active = false;
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 14
0
 internal static void CheckFixed() {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     foreach (string title in fixed_pages) {
         ContentPage page = db.ContentPages.Where(x => x.Title.ToLower().Equals(title.ToLower())).FirstOrDefault<ContentPage>();
         if (page == null) {
             page = new ContentPage {
                 Title = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(title),
                 content = ""
             };
             db.ContentPages.InsertOnSubmit(page);
         }
     }
     db.SubmitChanges();
 }
Ejemplo n.º 15
0
 public static void Delete(int id = 0)
 {
     try
     {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         Comment c = db.Comments.Where(x => x.commentID == id).FirstOrDefault<Comment>();
         c.active = false;
         db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 16
0
        internal static string Delete(int id) {
            try {
                EcommercePlatformDataContext db = new EcommercePlatformDataContext();
                Newsletter nw = new Newsletter();

                nw = db.Newsletters.Where(x => x.ID.Equals(id)).FirstOrDefault<Newsletter>();

                db.Newsletters.DeleteOnSubmit(nw);
                db.SubmitChanges();

                return "";
            } catch (Exception e) {
                return e.Message;
            }
        }
Ejemplo n.º 17
0
 public ActionResult Add(string ipaddress)
 {
     if (ipaddress != null && ipaddress.Trim() != "") {
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         // check if ip already exists
         FTPFirewall ip = new FTPFirewall();
         try {
             ip = db.FTPFirewalls.Where(x => x.ipaddress.Equals(ipaddress.Trim())).First<FTPFirewall>();
         } catch {
             ip.ipaddress = ipaddress;
             db.FTPFirewalls.InsertOnSubmit(ip);
             db.SubmitChanges();
         }
     }
     return RedirectToAction("Index");
 }
Ejemplo n.º 18
0
        internal static void Delete(int id)
        {
            Location loc = new Location();
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();

            loc = db.Locations.Where(x => x.locationID.Equals(id)).FirstOrDefault<Location>(); // Get the Location record
            string places_reference = loc.places_reference;

            db.Locations.DeleteOnSubmit(loc); // Delete it
            db.SubmitChanges(); // Commit

            // Check if it has a Google Places refernce
            if (places_reference != null && places_reference.Length > 0) {
                Geocoding.DeletePlaceEntry(places_reference);
            }
        }
Ejemplo n.º 19
0
        internal static void Add(string name, string email) {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            Newsletter exists = new Newsletter();

            // Check for existing
            exists = db.Newsletters.Where(x => x.Email.Equals(email)).FirstOrDefault<Newsletter>();
            if (exists != null) { throw new Exception("We are already sending the newsletter to " + email); }

            Newsletter nw = new Newsletter {
                Name = name,
                Email = email,
                DateAdded = DateTime.UtcNow,
                Unsubscribe = Guid.NewGuid()
            };
            db.Newsletters.InsertOnSubmit(nw);
            db.SubmitChanges();
        }
Ejemplo n.º 20
0
        public static void RemovePlaceReference(int id) {

            // Instantiate our database and Location object
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            Location loc = new Location();

            // Get the location from the db
            loc = db.Locations.Where(x => x.locationID.Equals(id)).FirstOrDefault<Location>();

            // Update Google Places reference
            loc.places_id = "";
            loc.places_reference = "";
            loc.places_status = "";

            // Commit to db
            db.SubmitChanges();
        }
Ejemplo n.º 21
0
 public static int Save(int id = 0, string name = "") {
     EcommercePlatformDataContext db = new EcommercePlatformDataContext();
     BlogCategory category = new BlogCategory();
     try {
         category = db.BlogCategories.Where(x => x.blogCategoryID == id).FirstOrDefault<BlogCategory>();
         category.name = name;
         category.slug = UDF.GenerateSlug(name);
     } catch {
         category = new BlogCategory {
             name = name,
             slug = UDF.GenerateSlug(name),
             active = true
         };
         db.BlogCategories.InsertOnSubmit(category);
     }
     db.SubmitChanges();
     return category.blogCategoryID;
 }
        internal static void AddParent(int id, int parent)
        {
            try {
                EcommercePlatformDataContext db = new EcommercePlatformDataContext();

                // Make sure there isn't already a listing for this
                ContentNesting exists = db.ContentNestings.Where(x => x.pageID.Equals(id) && x.parentID.Equals(parent)).FirstOrDefault<ContentNesting>();
                if (exists != null && exists.ID > 0) {
                    throw new Exception("Relationship exists.");
                }

                ContentNesting nest = new ContentNesting {
                    pageID = id,
                    parentID = parent
                };
                db.ContentNestings.InsertOnSubmit(nest);
                db.SubmitChanges();
            } catch (Exception) { }
        }
Ejemplo n.º 23
0
 public string CreateGroup(string name = "") {
     try {
         if(name.Trim() == "") {
             throw new Exception("Setting Group must have a name.");
         }
         SettingGroup g = new SettingGroup {
             name = name
         };
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         if (db.SettingGroups.Where(x => x.name.ToLower().Trim().Equals(name.Trim().ToLower())).Count() == 0) {
             db.SettingGroups.InsertOnSubmit(g);
             db.SubmitChanges();
         } else {
             throw new Exception("A setting group called " + name + " already exists");
         }
         return JsonConvert.SerializeObject(g);
     } catch (Exception e) {
         return e.Message;
     }
 }
Ejemplo n.º 24
0
        internal static void Save(int id, string Name, string Phone, string Fax, string Street1, string Street2, string City, int State, string PostalCode, out DistributionCenter dc, out List<string> errors)
        {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            dc = new DistributionCenter();
            errors = new List<string>();

            if (id != 0) {
                dc = db.DistributionCenters.Where(x => x.ID.Equals(id)).FirstOrDefault<DistributionCenter>();
            }
            try {
                // Validate the fields
                if (Name.Length == 0) { throw new Exception(); } else { dc.Name = Name; }
                if (Phone.Length == 0) { throw new Exception(); } else { dc.Phone = Phone; }
                if (Street1.Length == 0) { throw new Exception(); } else { dc.Street1 = Street1; }
                if (City.Length == 0) { throw new Exception(); } else { dc.City = City; }
                if (State == 0) { throw new Exception(); } else { dc.State = State; }
                if (PostalCode.Length == 0) { throw new Exception(); } else { dc.PostalCode = PostalCode; }
                dc.Fax = Fax;
                dc.Street2 = Street2;

                // Geocode the DC
                GeocodingResponse geo = Geocoding.GetGeoLocation(dc.Street1 + " " + dc.Street2, dc.City, 0, dc.PostalCode, dc.State1.Country.abbr, dc.State1.abbr);
                LatitudeLongitude latLon = new LatitudeLongitude();
                if (geo.results.Count > 0) {
                    latLon = geo.results[0].geometry.location;
                    dc.Latitude = latLon.lat;
                    dc.Longitude = latLon.lng;
                } else {
                    errors.Add("Failed to retrieve geographical location.");
                }

                if (errors.Count == 0) {
                    if (id == 0) {
                        db.DistributionCenters.InsertOnSubmit(dc);
                    }
                    db.SubmitChanges();
                }
            } catch (Exception e) {
                errors.Add(e.Message);
            }
        }
Ejemplo n.º 25
0
        public static Testimonial Add(string first_name = "", string last_name = "", string location = "", string testimonial = "") {
            Testimonial t = new Testimonial();
            try {
                EcommercePlatformDataContext db = new EcommercePlatformDataContext();
                t = new Testimonial {
                    testimonial1 = testimonial,
                    first_name = first_name,
                    last_name = last_name,
                    location = location,
                    dateAdded = DateTime.UtcNow,
                    approved = false,
                    active = true,
                };
                db.Testimonials.InsertOnSubmit(t);
                db.SubmitChanges();
                return t;

            } catch {
                return t;
            }
        }
Ejemplo n.º 26
0
 public string AddSetting(string sname = "", int gid = 0, bool isImage = false) {
     try {
         if (sname.Trim() == "") {
             throw new Exception("Setting must have a name.");
         }
         Setting s = new Setting {
             name = sname,
             groupID = gid,
             isImage = isImage,
         };
         EcommercePlatformDataContext db = new EcommercePlatformDataContext();
         if (db.Settings.Where(x => x.name.ToLower().Trim().Equals(sname.ToLower().Trim())).Count() == 0) {
             db.Settings.InsertOnSubmit(s);
             db.SubmitChanges();
         } else {
             throw new Exception("A Setting named " + sname + " already exists!");
         }
         return JsonConvert.SerializeObject(s);
     } catch (Exception e) {
         return e.Message;
     }
 }
Ejemplo n.º 27
0
        public ActionResult Comment(int id = 0, string name = "", string email = "", string comment_text = "") {
            BlogPost post = PostModel.GetById(id);
            string postdate = String.Format("{0:M-d-yyyy}", post.publishedDate);
            try {
                if (!(Models.ReCaptcha.ValidateCaptcha(System.Web.HttpContext.Current, Request.Form["recaptcha_challenge_field"], Request.Form["recaptcha_response_field"]))) {
                    throw new Exception("Recaptcha Validation Failed.");
                }
                if (id == 0) { throw new Exception("You must be on a blog post to add a comment"); }
                if (name == "") { throw new Exception("You must enter your name"); }
                if (email != "" & (!IsValidEmail(email))) { throw new Exception("Your email address is not a valid format."); }
                if (comment_text.Trim() == "") { throw new Exception("You must enter a comment"); }

                EcommercePlatformDataContext db = new EcommercePlatformDataContext();
                Comment comment = new Comment {
                    blogPostID = id,
                    name = name,
                    email = email,
                    comment_text = Regex.Replace(comment_text.Trim(),"<.*?>",string.Empty),
                    createdDate = DateTime.Now,
                    active = true,
                    approved = false
                };
                db.Comments.InsertOnSubmit(comment);
                db.SubmitChanges();
                string message = "Your comment has been submitted for approval.";
                return RedirectToRoute("BlogPost", new { message = message, title = post.slug, date = postdate });
            } catch (Exception e) {
                return RedirectToRoute("BlogPost", new { err = e.Message, title = post.slug, date = postdate, email = email, name = name, comment_text = comment_text });
            }
        }
Ejemplo n.º 28
0
        internal void ReadShippingNotification(string editext) {
            string trackingcode = "";
            string purchaseOrderID = "";
            string shipmentNumber = "";
            string weight = "";
            Cart order = new Cart();
            List<Shipment> shipments = new List<Shipment>();
            DateTime shipdate = DateTime.Now;
            Settings settings = new Settings();
            string EDIPOPreface = settings.Get("EDIPOPreface");

            List<string> edilines = editext.Split('~').ToList<string>();
            foreach (string line in edilines) {
                List<string> lineelements = line.Split('*').ToList<string>();
                switch (lineelements[0]) {
                    case "ST":
                        // Beginning of invoice
                        order = new Cart();
                        shipments = new List<Shipment>();
                        weight = "";
                        break;
                    case "BSN":
                        // Original Shipment Number from Shipper
                        shipmentNumber = lineelements[2];
                        break;
                    case "PRF":
                        // Purchase Order Reference
                        purchaseOrderID = lineelements[1];
                        if (EDIPOPreface != "") {
                            purchaseOrderID = purchaseOrderID.Replace(EDIPOPreface, "");
                        }
                        break;
                    case "REF":
                        // Tracking Code reference
                        trackingcode = lineelements[2];
                        Shipment shipment = new Shipment {
                            tracking_number = trackingcode
                        };
                        shipments.Add(shipment);
                        break;
                    case "DTM":
                        shipdate = Convert.ToDateTime(lineelements[2].Substring(4, 2) + "/" + lineelements[2].Substring(6, 2) + "/20" + lineelements[2].Substring(2, 2));
                        break;
                    case "TD1":
                        weight = lineelements[7] + " " + lineelements[8];
                        break;
                    case "SE":
                        // End of Invoice
                        try {
                            order = new Cart().GetByPaymentID(Convert.ToInt32(purchaseOrderID));
                            order.SetStatus((int)OrderStatuses.Shipped);
                            foreach (Shipment s in shipments) {
                                s.order_id = order.ID;
                                s.dateShipped = shipdate;
                                s.shipment_number = shipmentNumber;
                                s.weight = weight;
                            }
                            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
                            db.Shipments.InsertAllOnSubmit(shipments);
                            db.SubmitChanges();
                            order.SendShippingNotification();
                        } catch { }
                        break;
                }
            }
        }
Ejemplo n.º 29
0
        internal static void DeletePage(int id) {
            if (id == 0) { throw new Exception("Invalid refernece to ContentPage"); }
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            
            // Get and delete the menu options the reference this page
            List<ContentNesting> nestings = db.ContentNestings.Where(x => x.pageID.Equals(id) || x.parentID.Equals(id)).ToList<ContentNesting>();
            db.ContentNestings.DeleteAllOnSubmit<ContentNesting>(nestings);

            // Get and delete the ContentPage record
            ContentPage page = db.ContentPages.Where(x => x.ID.Equals(id)).FirstOrDefault<ContentPage>();
            db.ContentPages.DeleteOnSubmit(page);

            db.SubmitChanges();
        }
Ejemplo n.º 30
0
        internal static void RemoveParent(int id, int parent) {
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            ContentNesting nesting = new ContentNesting();
            nesting = db.ContentNestings.Where(x => x.parentID.Equals(parent) && x.pageID.Equals(id)).FirstOrDefault<ContentNesting>();

            db.ContentNestings.DeleteOnSubmit(nesting);
            db.SubmitChanges();
        }