public static GeocodingResponse GetGeoLocation(string city, int stateID, string zip, string countryCode = "US", string StateProvidence = "") { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); string abbr = ""; if (stateID != 0) { State state = db.States.Where(x => x.stateID.Equals(stateID)).FirstOrDefault(); abbr = state.abbr; countryCode = state.Country.abbr; } else { abbr = StateProvidence; } string url = "https://maps.googleapis.com/maps/api/geocode/json?address="; url += HttpUtility.UrlEncode(city + ", " + abbr + " " + zip + " " + countryCode); url += "&sensor=false"; WebClient wc = new WebClient(); wc.Proxy = null; string resp = wc.DownloadString(url); GeocodingResponse geo = new JavaScriptSerializer().Deserialize<GeocodingResponse>(resp); return geo; } catch (Exception) { return new GeocodingResponse(); } }
public static List<PrettyLocation> GetAll() { List<PrettyLocation> locs = new List<PrettyLocation>(); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); locs = (from l in db.Locations join s in db.States on l.stateID equals s.stateID select new PrettyLocation { locationID = l.locationID, name = l.name, phone = l.phone, fax = l.fax, email = l.email, address = l.address, city = l.city, stateID = l.stateID, zip = l.zip, isPrimary = l.isPrimary, latitude = l.latitude, longitude = l.longitude, places_id = l.places_id, places_reference = l.places_reference, places_status = l.places_status, foursquare_id = l.foursquare_id, abbr = s.abbr, state = s.state1, Services = (from serv in db.Services join ls in db.LocationServices on serv.ID equals ls.serviceID where ls.locationID.Equals(l.locationID) select serv).ToList<Service>() }).OrderBy(x => x.locationID).ToList<PrettyLocation>(); return locs; }
public static CommentWithPost Get(int id = 0) { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); CommentWithPost comment = new CommentWithPost(); comment = (from c in db.Comments where c.commentID.Equals(id) select new CommentWithPost { commentID = c.commentID, blogPostID = c.blogPostID, name = c.name, email = c.email, comment_text = c.comment_text, createdDate = c.createdDate, approved = c.approved, active = c.active, post = (from p in db.BlogPosts where p.blogPostID.Equals(c.blogPostID) select p).First<BlogPost>() }).First<CommentWithPost>(); return comment; } catch { return new CommentWithPost(); } }
public static List<CommentWithPost> GetAll() { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); List<CommentWithPost> comments = new List<CommentWithPost>(); comments = (from c in db.Comments where c.active.Equals(true) orderby c.approved, c.createdDate select new CommentWithPost { commentID = c.commentID, blogPostID = c.blogPostID, name = c.name, email = c.email, comment_text = c.comment_text, createdDate = c.createdDate, approved = c.approved, active = c.active, post = (from p in db.BlogPosts where p.blogPostID.Equals(c.blogPostID) select p).First<BlogPost>() }).ToList<CommentWithPost>(); return comments; } catch { return new List<CommentWithPost>(); } }
public static bool allowConnection(string ipaddress) { bool hasPermission = false; EcommercePlatformDataContext db = new EcommercePlatformDataContext(); hasPermission = db.FTPFirewalls.Where(x => x.ipaddress.Equals(ipaddress.Trim())).Count() > 0; return hasPermission; }
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"); }
public static List<PostWithCategories> GetAll() { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); List<PostWithCategories> posts = new List<PostWithCategories>(); posts = (from p in db.BlogPosts where p.active.Equals(true) orderby p.publishedDate, p.createdDate select new PostWithCategories { blogPostID = p.blogPostID, post_title = p.post_title, slug = p.slug, profileID = p.profileID, post_text = p.post_text, publishedDate = p.publishedDate, createdDate = p.createdDate, lastModified = p.lastModified, meta_title = p.meta_title, meta_description = p.meta_description, active = p.active, author = GetAuthor(p.profileID), categories = (from c in db.BlogCategories join pc in db.BlogPost_BlogCategories on c.blogCategoryID equals pc.blogCategoryID where pc.blogPostID.Equals(p.blogPostID) select c).ToList<BlogCategory>(), comments = (from cm in db.Comments where cm.blogPostID.Equals(p.blogPostID) && cm.approved.Equals(true) && cm.active.Equals(true) select cm).ToList<Comment>(), mod_comments = (from cm in db.Comments where cm.blogPostID.Equals(p.blogPostID) && cm.approved.Equals(false) && cm.active.Equals(true) select cm).ToList<Comment>() }).ToList<PostWithCategories>(); return posts; } catch (Exception e) { return new List<PostWithCategories>(); } }
public static PostWithCategories Get(string date = "", string title = "") { try { DateTime post_date = Convert.ToDateTime(date); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); PostWithCategories post = new PostWithCategories(); post = (from p in db.BlogPosts where p.slug.Equals(title) && Convert.ToDateTime(p.publishedDate).Day.Equals(post_date.Day) && Convert.ToDateTime(p.publishedDate).Year.Equals(post_date.Year) && Convert.ToDateTime(p.publishedDate).Month.Equals(post_date.Month) select new PostWithCategories { blogPostID = p.blogPostID, post_title = p.post_title, post_text = p.post_text, slug = p.slug, publishedDate = p.publishedDate, createdDate = p.createdDate, lastModified = p.lastModified, meta_title = p.meta_title, meta_description = p.meta_description, active = p.active, author = GetAuthor(p.profileID), categories = (from c in db.BlogCategories join pc in db.BlogPost_BlogCategories on c.blogCategoryID equals pc.blogCategoryID where pc.blogPostID.Equals(p.blogPostID) select c).ToList<BlogCategory>(), comments = (from cm in db.Comments where cm.blogPostID.Equals(p.blogPostID) && cm.active.Equals(true) && cm.approved.Equals(true) select cm).ToList<Comment>() }).First<PostWithCategories>(); return post; } catch (Exception e) { return new PostWithCategories(); } }
public static List<PostWithCategories> GetAllPublished(int page = 1, int pageSize = 5) { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); List<PostWithCategories> posts = new List<PostWithCategories>(); posts = (from p in db.BlogPosts where p.publishedDate.Value <= DateTime.UtcNow && p.active.Equals(true) orderby p.publishedDate descending select new PostWithCategories { blogPostID = p.blogPostID, post_title = p.post_title, post_text = p.post_text, slug = p.slug, publishedDate = p.publishedDate, createdDate = p.createdDate, lastModified = p.lastModified, keywords = p.keywords, meta_title = p.meta_title, meta_description = p.meta_description, active = p.active, author = GetAuthor(p.profileID), categories = (from c in db.BlogCategories join pc in db.BlogPost_BlogCategories on c.blogCategoryID equals pc.blogCategoryID where pc.blogPostID.Equals(p.blogPostID) select c).ToList<BlogCategory>(), comments = (from cm in db.Comments where cm.blogPostID.Equals(p.blogPostID) && cm.active.Equals(true) && cm.approved.Equals(true) select cm).ToList<Comment>() }).Skip((page - 1) * pageSize).Take(pageSize).ToList(); return posts; } catch { return new List<PostWithCategories>(); } }
public static List<Archive> GetMonths() { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); List<Archive> archives = new List<Archive>(); archives = (from p in db.BlogPosts where p.publishedDate.Value != null && p.publishedDate.Value <= DateTime.Now && p.active.Equals(true) orderby p.publishedDate.Value.Year descending, p.publishedDate.Value.Month descending select new Archive { monthnum = Convert.ToInt16(Convert.ToDateTime(p.publishedDate).Month.ToString()), month = Convert.ToDateTime(p.publishedDate).Month.ToString(), year = Convert.ToDateTime(p.publishedDate).Year.ToString() }).Distinct().ToList<Archive>(); archives = (from a in archives orderby a.year descending, a.monthnum select a).Distinct().ToList<Archive>(); return archives; } catch { return new List<Archive>(); } }
internal Dictionary<string, string> Populate() { Dictionary<string, string> settings = new Dictionary<string, string>(); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); settings = db.Settings.Select(p => new { p.name, p.value }).AsEnumerable().ToDictionary(kvp => kvp.name, kvp => kvp.value); return settings; }
internal static List<Newsletter> GetAll() { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); return db.Newsletters.ToList<Newsletter>(); } catch (Exception) { return new List<Newsletter>(); } }
public static int CountAll() { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); return db.Testimonials.Where(x => x.active == true).Where(x => x.approved == true).Count(); } catch { return 0; } }
public ActionResult Index() { List<FTPFirewall> ipaddresses = new List<FTPFirewall>(); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); ipaddresses = db.FTPFirewalls.ToList<FTPFirewall>(); ViewBag.ipaddresses = ipaddresses; return View(); }
public static List<Testimonial> GetAll(int page = 1, int pageSize = 10) { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); return db.Testimonials.Where(x => x.active == true).Where(x => x.approved == true).OrderByDescending(x => x.dateAdded).Skip((page - 1) * pageSize).Take(pageSize).ToList<Testimonial>(); } catch { return new List<Testimonial>(); } }
public static Profile GetProfile(string username = "", string pass = "") { Profile p = new Profile(); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); string encpass = EncryptString(pass); p = db.Profiles.Where(x => x.username.Equals(username) && x.password.Equals(encpass)).First<Profile>(); return p; }
internal static ContentPage GetPage(int id) { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); return db.ContentPages.Where(x => x.ID.Equals(id)).FirstOrDefault<ContentPage>(); } catch (Exception) { return new ContentPage(); } }
internal static List<ContentPage> GetSitemap() { List<ContentPage> pages = new List<ContentPage>(); List<string> excluded = new List<string> { "about us", "contact", "faq", "homepage", "privacy policy", "newsletter", "sitemap" }; try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); pages = db.ContentPages.Where(x => x.visible.Equals(true) && !excluded.Contains(x.Title.Trim().ToLower())).AsParallel().OrderBy(x => x.Title).ToList(); } catch { }; return pages; }
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(); }
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(); }
public static Invoice GetInvoiceByID(string invoiceID) { Invoice invoice = new Invoice(); try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); invoice = db.Invoices.Where(x => x.number.Equals(invoiceID)).FirstOrDefault<Invoice>(); } catch { }; return invoice; }
public static List<Cart> GetOrdersByDateRange(DateTime start, DateTime end) { List<Cart> orders = new List<Cart>(); try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); orders = db.Carts.Where(x => x.Payment.created >= start.ToUniversalTime()).Where(x => x.Payment.created <= end.ToUniversalTime()).Where(x => x.voided != true).ToList<Cart>(); } catch { }; return orders; }
public static List<Invoice> GetInvoicesByDateRange(DateTime start, DateTime end) { List<Invoice> invoices = new List<Invoice>(); try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); invoices = db.Invoices.Where(x => x.created > start && x.created <= end).ToList<Invoice>(); } catch { }; return invoices; }
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(); }
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"); }
internal static int GetPageID(string title = "") { try { int id = 0; EcommercePlatformDataContext db = new EcommercePlatformDataContext(); id = db.ContentPages.Where(x => x.Title.ToUpper().Equals(title.ToUpper())).Select(x => x.ID).FirstOrDefault<int>(); return id; } catch (Exception) { return 0; } }
internal static ContentPage GetPageByTitle(string title) { try { ContentPage page = new ContentPage(); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); page = db.ContentPages.Where(x => x.Title.Trim().ToUpper().Equals(title.Trim().ToUpper())).FirstOrDefault<ContentPage>(); return page; } catch (Exception) { return null; } }
public static bool hasPermission(int profileID) { bool hasPermission = false; EcommercePlatformDataContext db = new EcommercePlatformDataContext(); hasPermission = (from m in db.Modules join pm in db.ProfileModules on m.id equals pm.moduleID where pm.profileID == profileID && m.name.ToLower().Equals("ftp") select m.id).Count() > 0; return hasPermission; }
// // GET: /Tester/ public string Index() { List<Location> locs = new List<Location>(); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); locs = db.Locations.OrderBy(x => x.locationID).ToList<Location>(); foreach (Location loc in locs) { Response.Write(loc.name + "\r\n"); } return ""; }
public static BlogCategory Get(int id = 0) { try { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); BlogCategory category = new BlogCategory(); category = db.BlogCategories.Where(x => x.blogCategoryID == id).Where(x => x.active == true).FirstOrDefault<BlogCategory>(); return category; } catch { return new BlogCategory(); } }